feat(valid)!: promote to v1.0.0 — JSON tag name resolution, bump xerrors to v1.0.0

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.
This commit is contained in:
2026-05-11 18:18:05 -06:00
parent 328b80c060
commit 943110600a
4 changed files with 35 additions and 4 deletions

View File

@@ -5,6 +5,25 @@ 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).
## [1.0.0] — 2026-05-12
### Added
- JSON tag name resolution — field names in error context now use the `json`
struct 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
- `xerrors` dependency 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.
[1.0.0]: https://code.nochebuena.dev/go/valid/releases/tag/v1.0.0
## [0.9.0] - 2026-03-18
### Added

2
go.mod
View File

@@ -3,7 +3,7 @@ module code.nochebuena.dev/go/valid
go 1.25
require (
code.nochebuena.dev/go/xerrors v0.9.0
code.nochebuena.dev/go/xerrors v1.0.0
github.com/go-playground/validator/v10 v10.30.1
)

4
go.sum
View File

@@ -1,5 +1,5 @@
code.nochebuena.dev/go/xerrors v0.9.0 h1:8wrDto7e44ZW1YPOnT6JrxYXTqnvNuKpAO1/5bcT4TE=
code.nochebuena.dev/go/xerrors v0.9.0/go.mod h1:mtXo7xscBreCB7w7smlBP5Onv8H1HVohCvF0I/VXbAY=
code.nochebuena.dev/go/xerrors v1.0.0 h1:si24SFGa7cHwAxbu75AAEB+a3qRmF118F/BM2SFI7VI=
code.nochebuena.dev/go/xerrors v1.0.0/go.mod h1:mtXo7xscBreCB7w7smlBP5Onv8H1HVohCvF0I/VXbAY=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/gabriel-vasile/mimetype v1.4.12 h1:e9hWvmLYvtp846tLHam2o++qitpguFiYCKbn0w9jyqw=

View File

@@ -2,6 +2,8 @@ package valid
import (
"errors"
"reflect"
"strings"
"code.nochebuena.dev/go/xerrors"
playground "github.com/go-playground/validator/v10"
@@ -33,13 +35,23 @@ func WithMessageProvider(mp MessageProvider) Option {
}
// New returns a Validator. Without options, DefaultMessages (English) is used.
// Field names in error context use the json struct tag when available,
// falling back to the Go field name.
func New(opts ...Option) Validator {
cfg := &config{mp: DefaultMessages}
for _, o := range opts {
o(cfg)
}
v := playground.New()
v.RegisterTagNameFunc(func(fld reflect.StructField) string {
name := strings.SplitN(fld.Tag.Get("json"), ",", 2)[0]
if name == "" || name == "-" {
return fld.Name
}
return name
})
return &validator{
v: playground.New(),
v: v,
mp: cfg.mp,
}
}