Library API
Import
Section titled “Import”import ( "context" "fmt"
mdgovalidator "github.com/larsartmann/md-go-validator/pkg" "github.com/larsartmann/md-go-validator/pkg/languages" "github.com/larsartmann/md-go-validator/pkg/types")Create a Validator
Section titled “Create a Validator”validator := mdgovalidator.New(true). WithLanguages([]languages.Language{ languages.LangGo, languages.LangTypeScript, })Validate a File
Section titled “Validate a File”ctx := context.Background()results, err := validator.ValidateFile(ctx, "README.md")if err != nil { panic(err)}
for _, r := range results { if r.HasError() { fmt.Printf("Error at line %s: %v\n", r.LineNumber, r.Error) }}Validate a Directory
Section titled “Validate a Directory”results, err := validator.ValidateDirectory(ctx, "docs/")Streaming Validation
Section titled “Streaming Validation”Use ValidateDirectoryFunc for streaming results with a callback.
The callback returns an error to abort early, or nil to continue:
err := validator.ValidateDirectoryFunc(ctx, "docs/", func(r types.Result) error { if r.HasError() { fmt.Printf("%s:%s: %v\n", r.File, r.LineNumber, r.Error) } return nil})Builder Options
Section titled “Builder Options”| Method | Description |
|---|---|
New(verbose) |
Create a new validator (verbose controls per-block output) |
.WithLanguages([]Language) |
Set languages to validate |
.WithMaxFiles(n) |
Limit concurrent file processing |
.WithMaxBlocks(n) |
Limit blocks per file |
.WithConcurrency(n) |
Set worker pool size |
.WithRegistry(r) |
Inject a custom validator registry |
.WithExcludePatterns([]ExcludePattern) |
Glob patterns to exclude |
.WithSkipDirectives([]string) |
Custom skip directives |
.WithFileFilter(fn) |
Custom file filter function |
Result Type
Section titled “Result Type”type Result struct { File types.FileID // Source file path LineNumber types.LineNumber // 1-based line number Block types.BlockIndex // 1-based block index Code string // Code block content Status types.ValidationStatus // valid, error, or skipped Error error // Validation error (nil if valid) ErrorCode languages.ErrorCode // syntax, not_available, etc.}Adding a Custom Language Validator
Section titled “Adding a Custom Language Validator”Implement the Validator interface and register it:
type MyValidator struct{}
func (v *MyValidator) Language() languages.Language { return languages.Language("mylang")}
func (v *MyValidator) Validate(ctx context.Context, code string) error { // Your validation logic return nil}
func (v *MyValidator) IsAvailable() bool { return true}Then register it:
registry := languages.NewRegistry()if err := registry.Register(&MyValidator{}); err != nil { panic(err)}See Also
Section titled “See Also”- pkg.go.dev for full API reference
- Supported Languages for built-in validators
- Output Formats for result processing