Documentation
¶
Overview ¶
Package validate is a goboot plugin that generates request validation from field-constraint annotations (github.com/zombocoder/goboot issue #34). It registers a small set of Bean-Validation-style field annotations, checks them against their field types during analysis, and emits a runtime.Validator that the app wires onto goboot's existing HTTP bind→validate step:
// @Required // @Size(max=200) Title string `json:"title"`
generates a validator that rejects a missing or over-long Title with a 400 Problem listing every offending field.
Register it in goboot.yaml:
plugins: - github.com/zombocoder/goboot/plugins/validate
then wire the generated validator in the composition root:
httpDeps.Validator = generated.NewValidator()
The plugin drives generation entirely from its own annotations via the deeper plugin API (model.Application.Declarations, §46.5) and the request types on the analyzed routes; it reads no struct tags of its own.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Plugin ¶
type Plugin struct{}
Plugin implements the AnnotationProvider, Analyzer, and Generator capabilities.
func (*Plugin) Analyze ¶
func (*Plugin) Analyze(app *model.Application) []*annotation.Diagnostic
Analyze validates the field-constraint annotations against their field types (§46.1): @Min/@Max on non-numeric fields, @Size on non-length types, @Pattern/@Email on non-strings, malformed @Size bounds, uncompilable @Pattern regexes, and constraints on non-request types (which won't be enforced). It never mutates the model.
func (*Plugin) Annotations ¶
func (*Plugin) Annotations() []*annotation.Definition
Annotations registers the field-constraint annotations so the compiler recognizes them instead of reporting them as unknown.