-
Release v1.0.0 Stable
released this
2026-05-11 18:21:29 -06:00 | 1 commits to main since this releasev1.0.0
code.nochebuena.dev/go/validOverview
validv1.0.0 commits the struct validation API as stable. All v0.9.0 roadmap
items are resolved. The module ships a minimalValidatorinterface backed by
go-playground/validator/v10, fully decoupled from the public surface, with
pluggable i18n viaMessageProviderand tightxerrorsintegration.What Changed Since v0.9.0
New: JSON tag name resolution
Field names in error context now use the
jsonstruct tag when available,
falling back to the Go field name if no tag is defined or the tag is"-".Before (v0.9.0):
// struct field: EmailAddress string `json:"email_address" validate:"required"` xe.Fields()["field"] // → "EmailAddress"After (v1.0.0):
xe.Fields()["field"] // → "email_address"The same name is passed to
MessageProvider.Message(field, tag, param), so
custom providers automatically receive the JSON-facing field name.Structs without json tags are unaffected — the Go field name continues to be used.
Roadmap items resolved
Item Resolution Surfacing all validation errors ❌ No — Unwrap()exposesplayground.ValidationErrorsfor callers that need all failuresJSON tag name resolution ✅ Implemented via RegisterTagNameFuncFeedback on MessageProviderinterface✅ Stable — Message(field, tag, param string) stringcommittedCross-field validation helpers ❌ No — no recurring need identified from consumer codebases Full API (stable)
Validator— interface with a single method:Struct(v any) error.
Returnsnilif valid,*xerrors.ErrwithErrInvalidInputfor field failures
(first failing field), or*xerrors.ErrwithErrInternalfor non-struct input.New(opts ...Option) Validator— constructor. UsesDefaultMessages(English) unless overridden.WithMessageProvider(mp MessageProvider) Option— functional option to inject a custom message provider.MessageProvider— interface:Message(field, tag, param string) string.
fieldis the json tag name when available, otherwise the Go field name.DefaultMessages— built-in English provider forrequired,email,min,max, and a generic fallback.SpanishMessages— opt-in Spanish provider for the same tag set.Migration from v0.9.0
No breaking changes to the API surface. The only behavioral change is field
name resolution: if your structs definejsontags, the"field"key in
error context and thefieldargument toMessageProvider.Messagewill now
reflect the json tag name instead of the Go field name.go get code.nochebuena.dev/go/valid@v1.0.0Downloads