From adcf8ee66f93f53c9757935c85773f0fd1899183 Mon Sep 17 00:00:00 2001 From: Dmitri Aleksandrov Date: Mon, 19 Oct 2026 12:05:07 +0300 Subject: [PATCH] refactor!: move the modules of the integrations to integrations huma, gin and echo are in integrations/, the root of the repository has the core, the rules, problem and translator. BREAKING CHANGE: the module paths of the integrations are github.com/insei/valigo/integrations/huma, integrations/gin and integrations/echo. --- .github/dependabot.yml | 6 +++--- .github/workflows/go.yml | 3 ++- README.md | 2 +- docs/architecture/index.md | 2 +- docs/features/echo.md | 6 +++--- docs/features/gin.md | 6 +++--- docs/features/huma.md | 10 +++++----- docs/features/index.md | 6 +++--- docs/upgrading.md | 1 + docs/why-valigo.md | 2 +- {echo => integrations/echo}/echo.go | 0 {echo => integrations/echo}/echo_test.go | 2 +- {echo => integrations/echo}/go.mod | 4 ++-- {echo => integrations/echo}/go.sum | 0 {gin => integrations/gin}/gin.go | 0 {gin => integrations/gin}/gin_test.go | 2 +- {gin => integrations/gin}/go.mod | 4 ++-- {gin => integrations/gin}/go.sum | 0 {huma => integrations/huma}/go.mod | 4 ++-- {huma => integrations/huma}/go.sum | 0 {huma => integrations/huma}/huma.go | 0 {huma => integrations/huma}/huma_test.go | 2 +- {huma => integrations/huma}/openapi.go | 0 {huma => integrations/huma}/openapi_test.go | 2 +- mkdocs.yml | 2 +- scripts/modules.sh | 2 +- skills/valigo/SKILL.md | 6 +++--- 27 files changed, 38 insertions(+), 36 deletions(-) rename {echo => integrations/echo}/echo.go (100%) rename {echo => integrations/echo}/echo_test.go (97%) rename {echo => integrations/echo}/go.mod (88%) rename {echo => integrations/echo}/go.sum (100%) rename {gin => integrations/gin}/gin.go (100%) rename {gin => integrations/gin}/gin_test.go (98%) rename {gin => integrations/gin}/go.mod (94%) rename {gin => integrations/gin}/go.sum (100%) rename {huma => integrations/huma}/go.mod (73%) rename {huma => integrations/huma}/go.sum (100%) rename {huma => integrations/huma}/huma.go (100%) rename {huma => integrations/huma}/huma_test.go (98%) rename {huma => integrations/huma}/openapi.go (100%) rename {huma => integrations/huma}/openapi_test.go (99%) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 95a9b5a..6ecd4dc 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -4,9 +4,9 @@ updates: directories: - "/" - "/rules/uuid" - - "/huma" - - "/gin" - - "/echo" + - "/integrations/huma" + - "/integrations/gin" + - "/integrations/echo" - "/bench" - "/examples/*" schedule: diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 5c778de..ebb2f90 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -46,6 +46,7 @@ jobs: go.sum */go.sum rules/*/go.sum + integrations/*/go.sum - name: Build run: | @@ -90,7 +91,7 @@ jobs: cache-dependency-path: | go.sum rules/uuid/go.sum - huma/go.sum + integrations/*/go.sum examples/*/go.sum - name: Build and run the programs of the documentation and the skill diff --git a/README.md b/README.md index 458adf1..a5b9bdb 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,7 @@ and a conversion that doesn't fit the field doesn't compile: * Messages in English, German, Spanish, French and Russian with plural forms, the language of every request from the context, an `Accept-Language` middleware * `problem`: the errors as `application/problem+json` of RFC 9457 with JSON pointers * The rules as the keywords of JSON Schema, `vhuma.OpenAPI` puts them into the OpenAPI document of huma: the clients see `maxLength`, `format`, `enum` of the rules -* `github.com/insei/valigo/huma`, `github.com/insei/valigo/gin`, `github.com/insei/valigo/echo`: the rules of valigo in [huma](https://huma.rocks), [gin](https://gin-gonic.com) and [echo](https://echo.labstack.com) +* `github.com/insei/valigo/integrations/huma`, `github.com/insei/valigo/integrations/gin`, `github.com/insei/valigo/integrations/echo`: the rules of valigo in [huma](https://huma.rocks), [gin](https://gin-gonic.com) and [echo](https://echo.labstack.com) # Performance The same struct and rules, Intel Core i9-14900HX, Go 1.27.0, see [Performance](https://insei.github.io/valigo/latest/performance/): diff --git a/docs/architecture/index.md b/docs/architecture/index.md index bf58221..ac7679f 100644 --- a/docs/architecture/index.md +++ b/docs/architecture/index.md @@ -47,7 +47,7 @@ The rules append their errors to one pooled buffer of the validation, and `Valid | `rules/str`, `rules/num`, `rules/timex`, `rules/eq` | configurators of strings, numbers, times and comparable values built on `shared.Field[T]`, their conversions `str.Of`, `num.Of`, `num.Ptr`, `timex.Of`, `eq.Of`... and slice conversions | | `problem` | the problem details of RFC 9457 | | `github.com/insei/valigo/rules/uuid` | the separate module with the rules of `github.com/google/uuid`, the core doesn't depend on a uuid package | -| `github.com/insei/valigo/huma` | the separate module of the inputs of huma operations | +| `github.com/insei/valigo/integrations/huma`, `integrations/gin`, `integrations/echo` | the separate modules of huma, gin and echo | | `translator` | translator, in-memory storage, built-in locales, `Accept-Language` middleware | ## Contributing diff --git a/docs/features/echo.md b/docs/features/echo.md index a2461e0..2cc25a4 100644 --- a/docs/features/echo.md +++ b/docs/features/echo.md @@ -1,9 +1,9 @@ # echo -The module `github.com/insei/valigo/echo` validates the requests of [echo](https://echo.labstack.com) by valigo. +The module `github.com/insei/valigo/integrations/echo` validates the requests of [echo](https://echo.labstack.com) by valigo. ```bash -go get github.com/insei/valigo/echo@latest +go get github.com/insei/valigo/integrations/echo@latest ``` - `vecho.New(v)` is the `echo.Validator`: set `e.Validator = vecho.New(v)`, and `c.Validate(&req)` validates by the rules of valigo. @@ -23,7 +23,7 @@ import ( "strings" "github.com/insei/valigo" - vecho "github.com/insei/valigo/echo" + vecho "github.com/insei/valigo/integrations/echo" "github.com/insei/valigo/rules/str" "github.com/insei/valigo/shared" "github.com/labstack/echo/v4" diff --git a/docs/features/gin.md b/docs/features/gin.md index 0f5efc1..a6fb20c 100644 --- a/docs/features/gin.md +++ b/docs/features/gin.md @@ -1,9 +1,9 @@ # gin -The module `github.com/insei/valigo/gin` validates the requests of [gin](https://gin-gonic.com) by valigo. +The module `github.com/insei/valigo/integrations/gin` validates the requests of [gin](https://gin-gonic.com) by valigo. ```bash -go get github.com/insei/valigo/gin@latest +go get github.com/insei/valigo/integrations/gin@latest ``` - `vgin.New(v)` is the `binding.StructValidator` of gin: set `binding.Validator = vgin.New(v)`, and `c.ShouldBindJSON` and the other binding methods validate the requests by the rules of valigo. Slices are validated element by element, the location of an error has the index: `[1].email`. @@ -26,7 +26,7 @@ import ( "github.com/gin-gonic/gin/binding" "github.com/insei/fmap/v3" "github.com/insei/valigo" - vgin "github.com/insei/valigo/gin" + vgin "github.com/insei/valigo/integrations/gin" "github.com/insei/valigo/problem" "github.com/insei/valigo/rules/str" "github.com/insei/valigo/shared" diff --git a/docs/features/huma.md b/docs/features/huma.md index 0dab031..698fd54 100644 --- a/docs/features/huma.md +++ b/docs/features/huma.md @@ -1,13 +1,13 @@ # huma -The module `github.com/insei/valigo/huma` validates the inputs of [huma](https://huma.rocks) operations by valigo. The errors are the error details of huma with its locations — `body.email`, `query.limit`, `path.id` — in the 422 response of huma, and the messages are translated to the languages of the `Accept-Language` header. +The module `github.com/insei/valigo/integrations/huma` validates the inputs of [huma](https://huma.rocks) operations by valigo. The errors are the error details of huma with its locations — `body.email`, `query.limit`, `path.id` — in the 422 response of huma, and the messages are translated to the languages of the `Accept-Language` header. ```bash -go get github.com/insei/valigo/huma@latest +go get github.com/insei/valigo/integrations/huma@latest ``` ```go -import vhuma "github.com/insei/valigo/huma" +import vhuma "github.com/insei/valigo/integrations/huma" var validator = valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location)) @@ -38,7 +38,7 @@ import ( "github.com/danielgtaylor/huma/v2" "github.com/danielgtaylor/huma/v2/adapters/humago" "github.com/insei/valigo" - vhuma "github.com/insei/valigo/huma" + vhuma "github.com/insei/valigo/integrations/huma" "github.com/insei/valigo/rules/num" "github.com/insei/valigo/rules/str" ) @@ -134,7 +134,7 @@ import ( "github.com/danielgtaylor/huma/v2" "github.com/danielgtaylor/huma/v2/adapters/humago" "github.com/insei/valigo" - vhuma "github.com/insei/valigo/huma" + vhuma "github.com/insei/valigo/integrations/huma" "github.com/insei/valigo/rules/str" ) diff --git a/docs/features/index.md b/docs/features/index.md index 8963336..c96e003 100644 --- a/docs/features/index.md +++ b/docs/features/index.md @@ -47,6 +47,6 @@ The separate modules for the frameworks. | Page | What's inside | |---|---| | [JSON Schema](schema.md) | the rules as the keywords of JSON Schema for the generators of API schemas, `Constraints` | -| [huma](huma.md) | `github.com/insei/valigo/huma`: the rules in the `Resolve` of huma inputs with the locations of huma and in its OpenAPI document | -| [gin](gin.md) | `github.com/insei/valigo/gin`: the `binding.StructValidator` of gin and validation with the language of the request | -| [echo](echo.md) | `github.com/insei/valigo/echo`: the `echo.Validator` and validation with the language of the request | +| [huma](huma.md) | `github.com/insei/valigo/integrations/huma`: the rules in the `Resolve` of huma inputs with the locations of huma and in its OpenAPI document | +| [gin](gin.md) | `github.com/insei/valigo/integrations/gin`: the `binding.StructValidator` of gin and validation with the language of the request | +| [echo](echo.md) | `github.com/insei/valigo/integrations/echo`: the `echo.Validator` and validation with the language of the request | diff --git a/docs/upgrading.md b/docs/upgrading.md index 1531154..ca22276 100644 --- a/docs/upgrading.md +++ b/docs/upgrading.md @@ -6,6 +6,7 @@ Rules are still configured by pointers to the fields of the model, but the confi |---|---| | `github.com/insei/valigo/str`, `github.com/insei/valigo/num` | `github.com/insei/valigo/rules/str`, `github.com/insei/valigo/rules/num`, also `rules/eq` and `rules/timex` | | `github.com/insei/valigo/uuid` of the core module | the separate module `github.com/insei/valigo/rules/uuid` | +| — | the integrations are the separate modules `github.com/insei/valigo/integrations/huma`, `integrations/gin`, `integrations/echo` | | `b.String(&u.Name)` | `b.Field(&u.Name).As(str.Of)` | | `b.Number(&u.Age)` | `b.Field(&u.Age).As(num.Of)` | | `b.Number(&u.Score)` for `*int` | `b.Field(&u.Score).As(num.Ptr)` | diff --git a/docs/why-valigo.md b/docs/why-valigo.md index 8d12bb3..36bef2b 100644 --- a/docs/why-valigo.md +++ b/docs/why-valigo.md @@ -68,7 +68,7 @@ The rules of a slice check the slice itself and, by `Each`, every element with t ### Ready for HTTP APIs -The `problem` package writes the errors as `application/problem+json` of RFC 9457 with JSON pointers to the fields, the `github.com/insei/valigo/huma` module puts the rules into the inputs of huma operations with the locations of huma. See [HTTP problem details](features/problem.md) and [huma](features/huma.md). +The `problem` package writes the errors as `application/problem+json` of RFC 9457 with JSON pointers to the fields, the `github.com/insei/valigo/integrations/huma` module puts the rules into the inputs of huma operations with the locations of huma. See [HTTP problem details](features/problem.md) and [huma](features/huma.md). ### Errors that point to the field diff --git a/echo/echo.go b/integrations/echo/echo.go similarity index 100% rename from echo/echo.go rename to integrations/echo/echo.go diff --git a/echo/echo_test.go b/integrations/echo/echo_test.go similarity index 97% rename from echo/echo_test.go rename to integrations/echo/echo_test.go index f40bd56..4fce6bc 100644 --- a/echo/echo_test.go +++ b/integrations/echo/echo_test.go @@ -12,7 +12,7 @@ import ( "github.com/stretchr/testify/require" "github.com/insei/valigo" - vecho "github.com/insei/valigo/echo" + vecho "github.com/insei/valigo/integrations/echo" "github.com/insei/valigo/rules/str" "github.com/insei/valigo/shared" ) diff --git a/echo/go.mod b/integrations/echo/go.mod similarity index 88% rename from echo/go.mod rename to integrations/echo/go.mod index 0af509a..40184a1 100644 --- a/echo/go.mod +++ b/integrations/echo/go.mod @@ -1,8 +1,8 @@ -module github.com/insei/valigo/echo +module github.com/insei/valigo/integrations/echo go 1.27 -replace github.com/insei/valigo => ../ +replace github.com/insei/valigo => ../../ require ( github.com/insei/valigo v0.1.0 diff --git a/echo/go.sum b/integrations/echo/go.sum similarity index 100% rename from echo/go.sum rename to integrations/echo/go.sum diff --git a/gin/gin.go b/integrations/gin/gin.go similarity index 100% rename from gin/gin.go rename to integrations/gin/gin.go diff --git a/gin/gin_test.go b/integrations/gin/gin_test.go similarity index 98% rename from gin/gin_test.go rename to integrations/gin/gin_test.go index f01b90e..abe707b 100644 --- a/gin/gin_test.go +++ b/integrations/gin/gin_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" "github.com/insei/valigo" - vgin "github.com/insei/valigo/gin" + vgin "github.com/insei/valigo/integrations/gin" "github.com/insei/valigo/rules/str" "github.com/insei/valigo/shared" ) diff --git a/gin/go.mod b/integrations/gin/go.mod similarity index 94% rename from gin/go.mod rename to integrations/gin/go.mod index 0642a06..d537b98 100644 --- a/gin/go.mod +++ b/integrations/gin/go.mod @@ -1,8 +1,8 @@ -module github.com/insei/valigo/gin +module github.com/insei/valigo/integrations/gin go 1.27 -replace github.com/insei/valigo => ../ +replace github.com/insei/valigo => ../../ require ( github.com/gin-gonic/gin v1.12.0 diff --git a/gin/go.sum b/integrations/gin/go.sum similarity index 100% rename from gin/go.sum rename to integrations/gin/go.sum diff --git a/huma/go.mod b/integrations/huma/go.mod similarity index 73% rename from huma/go.mod rename to integrations/huma/go.mod index ff22f2e..321844c 100644 --- a/huma/go.mod +++ b/integrations/huma/go.mod @@ -1,8 +1,8 @@ -module github.com/insei/valigo/huma +module github.com/insei/valigo/integrations/huma go 1.27 -replace github.com/insei/valigo => ../ +replace github.com/insei/valigo => ../../ require ( github.com/danielgtaylor/huma/v2 v2.39.1 diff --git a/huma/go.sum b/integrations/huma/go.sum similarity index 100% rename from huma/go.sum rename to integrations/huma/go.sum diff --git a/huma/huma.go b/integrations/huma/huma.go similarity index 100% rename from huma/huma.go rename to integrations/huma/huma.go diff --git a/huma/huma_test.go b/integrations/huma/huma_test.go similarity index 98% rename from huma/huma_test.go rename to integrations/huma/huma_test.go index b93c434..a6f3541 100644 --- a/huma/huma_test.go +++ b/integrations/huma/huma_test.go @@ -14,7 +14,7 @@ import ( "github.com/stretchr/testify/require" "github.com/insei/valigo" - vhuma "github.com/insei/valigo/huma" + vhuma "github.com/insei/valigo/integrations/huma" "github.com/insei/valigo/rules/num" "github.com/insei/valigo/rules/str" ) diff --git a/huma/openapi.go b/integrations/huma/openapi.go similarity index 100% rename from huma/openapi.go rename to integrations/huma/openapi.go diff --git a/huma/openapi_test.go b/integrations/huma/openapi_test.go similarity index 99% rename from huma/openapi_test.go rename to integrations/huma/openapi_test.go index e0793c0..f91ef56 100644 --- a/huma/openapi_test.go +++ b/integrations/huma/openapi_test.go @@ -10,7 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/insei/valigo" - vhuma "github.com/insei/valigo/huma" + vhuma "github.com/insei/valigo/integrations/huma" "github.com/insei/valigo/rules/eq" "github.com/insei/valigo/rules/num" "github.com/insei/valigo/rules/str" diff --git a/mkdocs.yml b/mkdocs.yml index 301890f..0ee8e2b 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -119,7 +119,7 @@ plugins: num.Ptr, timex.Of, eq.Of, str.Slice...), so the compiler checks the field types and the rule arguments (Go 1.27 generic methods). Validation of valid objects doesn't allocate, absent values are skipped by all rules except Required, errors have field locations, translated messages (en, de, es, fr, ru), stable codes - and named params; the problem package writes RFC 9457 problem details, the github.com/insei/valigo/huma + and named params; the problem package writes RFC 9457 problem details, the github.com/insei/valigo/integrations/huma module validates huma inputs. The module path is github.com/insei/valigo. sections: Start: diff --git a/scripts/modules.sh b/scripts/modules.sh index f68d2a7..e752648 100644 --- a/scripts/modules.sh +++ b/scripts/modules.sh @@ -1,3 +1,3 @@ # The separate modules of the repository with their own go.mod, besides the core and the examples. # CI and the scripts lint, test and cover every one of them. -MODULES="rules/uuid huma gin echo" +MODULES="rules/uuid integrations/huma integrations/gin integrations/echo" diff --git a/skills/valigo/SKILL.md b/skills/valigo/SKILL.md index acd1b02..24d6793 100644 --- a/skills/valigo/SKILL.md +++ b/skills/valigo/SKILL.md @@ -188,15 +188,15 @@ func main() { ## gin -The module `github.com/insei/valigo/gin` (`vgin`): `binding.Validator = vgin.New(v)` makes `c.ShouldBindJSON` validate by valigo (messages in the default language, gin passes no request), `vgin.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`, get it by `errors.As`. +The module `github.com/insei/valigo/integrations/gin` (`vgin`): `binding.Validator = vgin.New(v)` makes `c.ShouldBindJSON` validate by valigo (messages in the default language, gin passes no request), `vgin.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`, get it by `errors.As`. ## echo -The module `github.com/insei/valigo/echo` (`vecho`): `e.Validator = vecho.New(v)` makes `c.Validate(&req)` validate by valigo (messages in the default language), `vecho.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`. +The module `github.com/insei/valigo/integrations/echo` (`vecho`): `e.Validator = vecho.New(v)` makes `c.Validate(&req)` validate by valigo (messages in the default language), `vecho.Validate(c, v, &req)` validates with the languages of `Accept-Language`; the error is `shared.Errors`. ## huma -The module `github.com/insei/valigo/huma` (`vhuma`): `valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location))` gives the locations of huma (`body.email`, `query.limit`, `path.id`), `func (i *Input) Resolve(ctx huma.Context) []error { return vhuma.Resolve(ctx, validator, i) }` validates the input with the languages of `Accept-Language`. +The module `github.com/insei/valigo/integrations/huma` (`vhuma`): `valigo.New(valigo.WithFieldLocationNamingFn(vhuma.Location))` gives the locations of huma (`body.email`, `query.limit`, `path.id`), `func (i *Input) Resolve(ctx huma.Context) []error { return vhuma.Resolve(ctx, validator, i) }` validates the input with the languages of `Accept-Language`. ## Translations