Documentation
¶
Overview ¶
Package validation wraps go-playground/validator/v10 and translates its FieldError slice into kernel/errors.FieldError values, producing a *errors.Error with Kind=KindValidation. It is the "shape validation" half of the two-layer validation strategy described in docs/blueprint/04 §5: struct-tag checks live here; domain / cross-field / rule-engine logic lives in module domain/validation.go and returns errors.E(KindValidation|KindRuleViolation…).
Import boundary: stdlib + kernel/errors + validator lib. Never module, app, adapters, or testkit.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Validator ¶
type Validator struct {
// contains filtered or unexported fields
}
Validator wraps a *validator.Validate instance. It is safe for concurrent use: go-playground/validator guarantees the *Validate value is read-only after construction, making concurrent Struct calls safe without additional synchronisation.
func New ¶
func New() *Validator
New constructs a Validator ready for use. It registers a TagNameFunc so that field paths in errors.FieldError values use the json tag name (e.g. "email_address") rather than the Go struct field name ("EmailAddress"). Fields without a json tag fall back to their Go field name.
func (*Validator) Struct ¶
Struct validates the exported fields of s using struct tags. On success it returns nil. On failure it returns a *errors.Error with Kind=KindValidation carrying one errors.FieldError per invalid field — all violations are collected (not short-circuited) so the caller receives the full picture in one round-trip.
If s is not a struct (or pointer-to-struct), Struct returns a KindInternal error: passing a non-struct is a programming mistake in the caller, not a user-input problem.