Resolve JSON tag name resolution roadmap item: field names in error context now use the json struct tag when available, falling back to the Go field name. Commits MessageProvider interface as stable. Bumps xerrors dependency from v0.9.0 to v1.0.0. API committed as stable.
2.6 KiB
2.6 KiB
Changelog
All notable changes to this module will be documented in this file.
The format is based on Keep a Changelog, and this module adheres to Semantic Versioning.
1.0.0 — 2026-05-12
Added
- JSON tag name resolution — field names in error context now use the
jsonstruct tag when available (e.g."email_address"instead of"EmailAddress"), falling back to the Go field name when no json tag is defined or the tag is"-".
Changed
xerrorsdependency bumped from v0.9.0 to v1.0.0.
Unchanged
All existing API (Validator, New, WithMessageProvider, MessageProvider,
DefaultMessages, SpanishMessages) is API-compatible with v0.9.0.
0.9.0 - 2026-03-18
Added
Validatorinterface with a singleStruct(v any) errormethod for struct tag validation.New(opts ...Option) Validatorconstructor; returns an English-language validator by default.Optionfunctional-option type for configuring aValidatorat construction time.WithMessageProvider(mp MessageProvider) Optionoption to replace the built-in message provider.MessageProviderinterface withMessage(field, tag, param string) string; implement to supply custom or localised messages.DefaultMessages(MessageProvider): built-in English messages forrequired,email,min,max, and a generic fallback.SpanishMessages(MessageProvider): opt-in Spanish translations for the same tag set.- Error behaviour: a failing struct field returns
*xerrors.Errwith codeErrInvalidInput; structured context keys"field"and"tag"are attached viaWithContext. The rawplayground.ValidationErrorsis chained viaWithErrorfor callers that need all failures. - Error behaviour: passing a non-struct value returns
*xerrors.Errwith codeErrInternal(wrappingplayground.InvalidValidationError). - Only the first failing field is surfaced per
Structcall; the full error slice is preserved in the error chain.
Design Notes
go-playground/validator/v10is used as the backend but is entirely hidden behind theValidatorinterface; no playground types appear in the public API.MessageProviderdecouples human-readable text from validation logic, enabling i18n without any changes to the core package.- A single
*playground.Validateinstance is created perValidator(not per call) to amortise the cost of reflection-based type caching.