Struct validation backed by go-playground/validator/v10 with xerrors integration and pluggable i18n message providers. What's included: - Validator interface with Struct(v any) error method - New(...Option) constructor with WithMessageProvider functional option - MessageProvider interface for i18n; DefaultMessages (EN) and SpanishMessages (ES) built in - ValidationErrors mapped to xerrors.ErrInvalidInput with field and tag context keys - InvalidValidationError (non-struct input) mapped to xerrors.ErrInternal - Full playground.ValidationErrors attached via WithError for callers needing all failures Tested-via: todo-api POC integration Reviewed-against: docs/adr/
30 lines
2.0 KiB
Markdown
30 lines
2.0 KiB
Markdown
# Changelog
|
|
|
|
All notable changes to this module will be documented in this file.
|
|
|
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
and this module adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
|
## [0.9.0] - 2026-03-18
|
|
|
|
### Added
|
|
|
|
- `Validator` interface with a single `Struct(v any) error` method for struct tag validation.
|
|
- `New(opts ...Option) Validator` constructor; returns an English-language validator by default.
|
|
- `Option` functional-option type for configuring a `Validator` at construction time.
|
|
- `WithMessageProvider(mp MessageProvider) Option` option to replace the built-in message provider.
|
|
- `MessageProvider` interface with `Message(field, tag, param string) string`; implement to supply custom or localised messages.
|
|
- `DefaultMessages` (`MessageProvider`): built-in English messages for `required`, `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.Err` with code `ErrInvalidInput`; structured context keys `"field"` and `"tag"` are attached via `WithContext`. The raw `playground.ValidationErrors` is chained via `WithError` for callers that need all failures.
|
|
- Error behaviour: passing a non-struct value returns `*xerrors.Err` with code `ErrInternal` (wrapping `playground.InvalidValidationError`).
|
|
- Only the first failing field is surfaced per `Struct` call; the full error slice is preserved in the error chain.
|
|
|
|
### Design Notes
|
|
|
|
- `go-playground/validator/v10` is used as the backend but is entirely hidden behind the `Validator` interface; no playground types appear in the public API.
|
|
- `MessageProvider` decouples human-readable text from validation logic, enabling i18n without any changes to the core package.
|
|
- A single `*playground.Validate` instance is created per `Validator` (not per call) to amortise the cost of reflection-based type caching.
|
|
|
|
[0.9.0]: https://code.nochebuena.dev/go/valid/releases/tag/v0.9.0
|