Update module github.com/gookit/validate to v2 #26

Open
renovate-bot wants to merge 1 commit from renovate/github.com-gookit-validate-2.x into master
Collaborator

This PR contains the following updates:

Package Change Age Confidence
github.com/gookit/validate v1.6.0v2.0.1 age confidence

Release Notes

gookit/validate (github.com/gookit/validate)

v2.0.1

Compare Source

Change Log

Refactor
  • refactor(validators): 比较家族 RV 化搬入 internal/validators (RFC R1) d90d91c
  • refactor(validators): 标量类型族 IsInt/IsString/IsSlice RV 化搬入 internal (RFC R2a) 5a89ab1
  • refactor(validators): 长度族 Length/MinLength/MaxLength RV 化搬入 internal (RFC R2b) c69fc22
  • refactor(validators): 枚举族 Enum/NotIn RV 化搬入 internal (RFC R2c) d079b28
  • refactor(validators): 取串热路径复用载体 String() 消二次反射 (RFC R2d) aeab5ee
  • refactor(data): 提取 StructData.tryGetRV 取值原语,TryGet 委托 (RFC R4.1) 7352c7f
  • refactor(fieldval): Src 懒化 + IsEmpty/String/calcLen 纯 RV + required 载体原生 (RFC R4.2a) 7fbd721
  • refactor(validate): valueValidate 改吃载体 *FieldValue (RFC R4.2b-1) 64b2429
Feature
  • feat(validators): 公开 FieldCtx 接口 + funcMeta 识别 func(FieldCtx)bool 形态 (RFC R3a) bd98903
  • feat(validators): callValidatorValue 按 style 分派 + func(FieldCtx)bool 自定义校验器落地 (RFC R3b) 80805f9
  • feat(validate): struct 源只读校验入口(Validate/ValidateErr/E)自动跳过 safeData 收集 854da39
Update
  • perf(validators): IsBool/IsUint/IsArray/IsMap 提升进 switch + internal RV 版 (RFC R2.5a) db65592
  • perf(validators): Contains/NotContains 提升进 switch 免 reflect.Call (RFC R2.5b) e0351f4
  • perf(validate): 结构体源经 tryGetRV+NewRV 懒构造载体,CheckErr 去 2 装箱 (RFC R4.2b-2) 503863d
  • perf(validators): valueCompare 非指针分支纯 RV,消除 CheckErr 最后 1 装箱 (RFC R4.3) 95431c1
  • perf(validate): scRV 缓存字段 reflect.Value,免 skipCollect 重读并闭合非指针边界 b60f8be
Other
  • docs(perf): RFC validator 入参 RV 化 + FieldLevel 自定义校验器 5260449
  • docs(perf): RFC 命名定为 FieldCtx + 补开发交接(R1 首步) 17dd47f
  • docs(perf): RFC §8 修正 Src 懒装箱触发条件描述 63092bf
  • docs: 更新 RV-native 重构后压测数据与架构现状(CheckErr 0 alloc) c4088a0
  • docs(readme): CheckErr struct-valid 3→0 allocs(RV-native 端到端去装箱) 8f63bfa
  • chore: reanme and merge some go files 59e87c0
  • docs: 同步 struct 源 Validate/ValidateErr 自动免收集后的分配数字 1516f07

v2.0.0

Compare Source

v2.0 keeps breaking changes intentionally minimal (5 items). Core API,
validator names, tag semantics and the DataFace interface are unchanged — most
projects upgrade by bumping the import path to /v2. See
docs/UPGRADE-v2.md for the full migration guide.

Breaking Changes
  • Module path github.com/gookit/validategithub.com/gookit/validate/v2
    (per Go Modules semantic import versioning). Update both go get and all
    import lines.
  • Minimum Go version 1.19 → 1.21 (go.mod).
  • Between signature Between(val any, min, max int64)
    Between(val, min, max any), now consistent with Gt/Lt via valueCompare
    (supports int / uint / float / string). Semantic change for fractional bounds:
    Between(2.9, 1, 2) was true (int64 truncation) and is now false (no more
    truncation). Tag/StringRule usage like between:1,2 is unaffected.
  • Removed deprecated ValueLen(v) — use goutil's reflects.Len(v) instead.
  • Sub-struct cascade now requires the parent field to carry a validate tag.
    Previously a sub-struct field (struct / *struct / slice-of-struct /
    map-of-struct) was always descended into to collect its inner rules. Now
    (CheckSubOnParentMarked defaults to true) cascade only happens when the
    parent field has a validate tag — the value may be empty (validate:""
    is enough to mark it); a named field with no validate tag is no
    longer descended into (Java @Valid-style opt-in). Anonymous embedded
    structs
    (e.g. type Bar struct { Foo }) are exempt — they are part of
    the parent and always cascade regardless of tag; only named sub-struct
    fields require the tag. To restore the v1 "always cascade" behavior globally:
    validate.Config(func(o *validate.GlobalOption){ o.CheckSubOnParentMarked = false }).
    See docs/UPGRADE-v2.md for migration details.

Note: the DataFace interface is unchanged (a redesign was planned during
v2.0 but rejected after profiling); custom DataFace implementers are unaffected.

New Features
  • AddCustomType(fn CustomTypeFunc, types ...any) — register an underlying
    value extractor for custom/wrapped types (e.g. sql.NullString, money types).
    The extracted value flows through the existing validation paths (required /
    numeric compare / length / string rules). CustomTypeFunc func(field reflect.Value) any; returning nil is treated as empty. Mirrors
    go-playground/validator's RegisterCustomTypeFunc. ResetCustomTypes() clears
    the registry. Zero overhead on the hot path when nothing is registered (atomic
    gate short-circuit).
  • NewFactory() + Factory.Struct / Factory.Map + (*Validation).Release()
    — opt-in pooled factory that reuses *Validation instances across many
    same-type validations, amortizing construction cost (allocs roughly halved in
    reuse scenarios). Non-default: Struct / Map / New behavior and lifecycle
    are unchanged.
Performance

Measured on Go 1.25 (count=6) against the v1.6.0 final:

Benchmark v1.6.0 v2.0 default
StructFlat 2295 ns / 34 allocs 1870 ns / 23 allocs (-18% / -32%)
StructNested 2137 ns / 34 allocs 1722 ns / 24 allocs (-19% / -29%)
MapValidate 3314 ns / 72 allocs 3350 ns / 72 allocs (flat)
ValValue 725 ns / 11 allocs 737 ns / 11 allocs (flat)
SliceOfStruct 10900 ns / 208 allocs (dynamic, flat)
FactoryStructReuse (new) 1633 ns / 11 allocs (-52% allocs vs non-factory)

Coverage 95.7% (v1.6.0 was 95.6%).

Internal
  • Pre-convert rule args at build time (drop the runtime convertArgsType).
  • Share immutable static template rules instead of cloning per instance.
  • Fix string validators panicking on non-string fields.
  • Split validators.go by category (compare / string / type files).
  • Sink pure-reflect helpers and fieldValue into internal/ (reflectx,
    fieldval).

Configuration

📅 Schedule: (UTC)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.

Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 Ignore: Close this PR and you won't be reminded about this update again.


  • If you want to rebase/retry this PR, check this box

This PR has been generated by Renovate Bot.

This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [github.com/gookit/validate](https://github.com/gookit/validate) | `v1.6.0` → `v2.0.1` | ![age](https://developer.mend.io/api/mc/badges/age/go/github.com%2fgookit%2fvalidate/v2.0.1?slim=true) | ![confidence](https://developer.mend.io/api/mc/badges/confidence/go/github.com%2fgookit%2fvalidate/v1.6.0/v2.0.1?slim=true) | --- ### Release Notes <details> <summary>gookit/validate (github.com/gookit/validate)</summary> ### [`v2.0.1`](https://github.com/gookit/validate/releases/tag/v2.0.1) [Compare Source](https://github.com/gookit/validate/compare/v2.0.0...v2.0.1) #### Change Log ##### Refactor - refactor(validators): 比较家族 RV 化搬入 internal/validators (RFC R1) [`d90d91c`](https://github.com/gookit/validate/commit/d90d91c96b3a462cad0e7169e9ce9b474627bdd3) - refactor(validators): 标量类型族 IsInt/IsString/IsSlice RV 化搬入 internal (RFC R2a) [`5a89ab1`](https://github.com/gookit/validate/commit/5a89ab1a1f58c24c95c1bcb68752771737e2dd59) - refactor(validators): 长度族 Length/MinLength/MaxLength RV 化搬入 internal (RFC R2b) [`c69fc22`](https://github.com/gookit/validate/commit/c69fc2246d492f559cab62fb20388370d5c07486) - refactor(validators): 枚举族 Enum/NotIn RV 化搬入 internal (RFC R2c) [`d079b28`](https://github.com/gookit/validate/commit/d079b2889b898fe33384d2ecbd3b90e8286f398b) - refactor(validators): 取串热路径复用载体 String() 消二次反射 (RFC R2d) [`aeab5ee`](https://github.com/gookit/validate/commit/aeab5eea5b315f4e79d944809784d174b9354b07) - refactor(data): 提取 StructData.tryGetRV 取值原语,TryGet 委托 (RFC R4.1) [`7352c7f`](https://github.com/gookit/validate/commit/7352c7f8475a7857d1250f56e60ef23e7def899b) - refactor(fieldval): Src 懒化 + IsEmpty/String/calcLen 纯 RV + required 载体原生 (RFC R4.2a) [`7fbd721`](https://github.com/gookit/validate/commit/7fbd7217dea49964aa784756407bca23b8aaaa87) - refactor(validate): valueValidate 改吃载体 \*FieldValue (RFC R4.2b-1) [`64b2429`](https://github.com/gookit/validate/commit/64b2429883d6f530db3a818fec24bba1e76a5da9) ##### Feature - feat(validators): 公开 FieldCtx 接口 + funcMeta 识别 func(FieldCtx)bool 形态 (RFC R3a) [`bd98903`](https://github.com/gookit/validate/commit/bd98903a5dd1eb6a37dc7641bc73e43056e88796) - feat(validators): callValidatorValue 按 style 分派 + func(FieldCtx)bool 自定义校验器落地 (RFC R3b) [`80805f9`](https://github.com/gookit/validate/commit/80805f989e990a27c9daf494b26d56256dace4d1) - feat(validate): struct 源只读校验入口(Validate/ValidateErr/E)自动跳过 safeData 收集 [`854da39`](https://github.com/gookit/validate/commit/854da39ed4337aec2ef0985df6b0b97ccbc613b7) ##### Update - perf(validators): IsBool/IsUint/IsArray/IsMap 提升进 switch + internal RV 版 (RFC R2.5a) [`db65592`](https://github.com/gookit/validate/commit/db6559227748118973868ec08b66f020b93a1ee6) - perf(validators): Contains/NotContains 提升进 switch 免 reflect.Call (RFC R2.5b) [`e0351f4`](https://github.com/gookit/validate/commit/e0351f42d4237650f70d2a80b23294b21295662f) - perf(validate): 结构体源经 tryGetRV+NewRV 懒构造载体,CheckErr 去 2 装箱 (RFC R4.2b-2) [`503863d`](https://github.com/gookit/validate/commit/503863d0eab2742ec298321cf9cc6727ba4b9731) - perf(validators): valueCompare 非指针分支纯 RV,消除 CheckErr 最后 1 装箱 (RFC R4.3) [`95431c1`](https://github.com/gookit/validate/commit/95431c162e51f42b449919e26219788d78d0e69f) - perf(validate): scRV 缓存字段 reflect.Value,免 skipCollect 重读并闭合非指针边界 [`b60f8be`](https://github.com/gookit/validate/commit/b60f8beb128aec014c57e4e1679d345450e7985f) ##### Other - docs(perf): RFC validator 入参 RV 化 + FieldLevel 自定义校验器 [`5260449`](https://github.com/gookit/validate/commit/526044931b330e23ee4c26567379c57630d611bd) - docs(perf): RFC 命名定为 FieldCtx + 补开发交接(R1 首步) [`17dd47f`](https://github.com/gookit/validate/commit/17dd47fd31f6c45a8c0819a2cb4e6aacf25ddd91) - docs(perf): RFC §8 修正 Src 懒装箱触发条件描述 [`63092bf`](https://github.com/gookit/validate/commit/63092bfa569850f8f2da68b620462a1b5355d6be) - docs: 更新 RV-native 重构后压测数据与架构现状(CheckErr 0 alloc) [`c4088a0`](https://github.com/gookit/validate/commit/c4088a01ca030e60fdf69a9b545360e216168fec) - docs(readme): CheckErr struct-valid 3→0 allocs(RV-native 端到端去装箱) [`8f63bfa`](https://github.com/gookit/validate/commit/8f63bfa2b9a127c1a9104c37eb4c265e2d79a2f0) - chore: reanme and merge some go files [`59e87c0`](https://github.com/gookit/validate/commit/59e87c05839109aef65f940e384ebc31efb72cc3) - docs: 同步 struct 源 Validate/ValidateErr 自动免收集后的分配数字 [`1516f07`](https://github.com/gookit/validate/commit/1516f07bbb0941733a138d11b8d9202950fa2e30) ### [`v2.0.0`](https://github.com/gookit/validate/blob/HEAD/CHANGELOG.md#v200) [Compare Source](https://github.com/gookit/validate/compare/v1.6.0...v2.0.0) v2.0 keeps breaking changes **intentionally minimal** (5 items). Core API, validator names, tag semantics and the `DataFace` interface are unchanged — most projects upgrade by bumping the import path to `/v2`. See [docs/UPGRADE-v2.md](docs/UPGRADE-v2.md) for the full migration guide. ##### Breaking Changes - **Module path** `github.com/gookit/validate` → `github.com/gookit/validate/v2` (per Go Modules semantic import versioning). Update both `go get` and all `import` lines. - **Minimum Go version** 1.19 → **1.21** (`go.mod`). - **`Between` signature** `Between(val any, min, max int64)` → `Between(val, min, max any)`, now consistent with `Gt`/`Lt` via `valueCompare` (supports int / uint / float / string). Semantic change for fractional bounds: `Between(2.9, 1, 2)` was `true` (int64 truncation) and is now `false` (no more truncation). Tag/`StringRule` usage like `between:1,2` is unaffected. - **Removed deprecated `ValueLen(v)`** — use goutil's `reflects.Len(v)` instead. - **Sub-struct cascade now requires the parent field to carry a `validate` tag.** Previously a sub-struct field (struct / `*struct` / slice-of-struct / map-of-struct) was **always** descended into to collect its inner rules. Now (`CheckSubOnParentMarked` defaults to **true**) cascade only happens when the parent field has a `validate` tag — the value may be **empty** (`validate:""` is enough to mark it); a **named** field with **no** `validate` tag is no longer descended into (Java `@Valid`-style opt-in). **Anonymous embedded structs** (e.g. `type Bar struct { Foo }`) are **exempt** — they are part of the parent and always cascade regardless of tag; only **named** sub-struct fields require the tag. To restore the v1 "always cascade" behavior globally: `validate.Config(func(o *validate.GlobalOption){ o.CheckSubOnParentMarked = false })`. See [docs/UPGRADE-v2.md](docs/UPGRADE-v2.md) for migration details. > Note: the `DataFace` interface is **unchanged** (a redesign was planned during > v2.0 but rejected after profiling); custom `DataFace` implementers are unaffected. ##### New Features - **`AddCustomType(fn CustomTypeFunc, types ...any)`** — register an underlying value extractor for custom/wrapped types (e.g. `sql.NullString`, money types). The extracted value flows through the existing validation paths (`required` / numeric compare / length / string rules). `CustomTypeFunc func(field reflect.Value) any`; returning `nil` is treated as empty. Mirrors go-playground/validator's `RegisterCustomTypeFunc`. `ResetCustomTypes()` clears the registry. Zero overhead on the hot path when nothing is registered (atomic gate short-circuit). - **`NewFactory()` + `Factory.Struct` / `Factory.Map` + `(*Validation).Release()`** — opt-in pooled factory that reuses `*Validation` instances across many same-type validations, amortizing construction cost (allocs roughly halved in reuse scenarios). Non-default: `Struct` / `Map` / `New` behavior and lifecycle are unchanged. ##### Performance Measured on Go 1.25 (count=6) against the v1.6.0 final: | Benchmark | v1.6.0 | v2.0 default | | ---------------------------- | ------------------- | ---------------------------------------------------- | | StructFlat | 2295 ns / 34 allocs | 1870 ns / 23 allocs (-18% / -32%) | | StructNested | 2137 ns / 34 allocs | 1722 ns / 24 allocs (-19% / -29%) | | MapValidate | 3314 ns / 72 allocs | 3350 ns / 72 allocs (flat) | | ValValue | 725 ns / 11 allocs | 737 ns / 11 allocs (flat) | | SliceOfStruct | — | 10900 ns / 208 allocs (dynamic, flat) | | **FactoryStructReuse** (new) | — | 1633 ns / **11 allocs** (-52% allocs vs non-factory) | Coverage 95.7% (v1.6.0 was 95.6%). ##### Internal - Pre-convert rule args at build time (drop the runtime `convertArgsType`). - Share immutable static template rules instead of cloning per instance. - Fix string validators panicking on non-string fields. - Split `validators.go` by category (compare / string / type files). - Sink pure-reflect helpers and `fieldValue` into `internal/` (`reflectx`, `fieldval`). </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0My4xMzguMyIsInVwZGF0ZWRJblZlciI6IjQzLjEzOC4zIiwidGFyZ2V0QnJhbmNoIjoibWFzdGVyIiwibGFiZWxzIjpbXX0=-->
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin renovate/github.com-gookit-validate-2.x:renovate/github.com-gookit-validate-2.x
git switch renovate/github.com-gookit-validate-2.x

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff renovate/github.com-gookit-validate-2.x
git switch renovate/github.com-gookit-validate-2.x
git rebase master
git switch master
git merge --ff-only renovate/github.com-gookit-validate-2.x
git switch renovate/github.com-gookit-validate-2.x
git rebase master
git switch master
git merge --no-ff renovate/github.com-gookit-validate-2.x
git switch master
git merge --squash renovate/github.com-gookit-validate-2.x
git switch master
git merge --ff-only renovate/github.com-gookit-validate-2.x
git switch master
git merge renovate/github.com-gookit-validate-2.x
git push origin master
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
paspo/mail-autoconfig!26
No description provided.