Update module github.com/gookit/validate to v2 #30
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "renovate/github.com-gookit-validate-2.x"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR contains the following updates:
v1.6.0→v2.0.1Release Notes
gookit/validate (github.com/gookit/validate)
v2.0.1Compare Source
Change Log
Refactor
d90d91c5a89ab1c69fc22d079b28aeab5ee7352c7f7fbd72164b2429Feature
bd9890380805f9854da39Update
db65592e0351f4503863d95431c1b60f8beOther
526044917dd47f63092bfc4088a08f63bfa59e87c01516f07v2.0.0Compare Source
v2.0 keeps breaking changes intentionally minimal (5 items). Core API,
validator names, tag semantics and the
DataFaceinterface are unchanged — mostprojects upgrade by bumping the import path to
/v2. Seedocs/UPGRADE-v2.md for the full migration guide.
Breaking Changes
github.com/gookit/validate→github.com/gookit/validate/v2(per Go Modules semantic import versioning). Update both
go getand allimportlines.go.mod).BetweensignatureBetween(val any, min, max int64)→Between(val, min, max any), now consistent withGt/LtviavalueCompare(supports int / uint / float / string). Semantic change for fractional bounds:
Between(2.9, 1, 2)wastrue(int64 truncation) and is nowfalse(no moretruncation). Tag/
StringRuleusage likebetween:1,2is unaffected.ValueLen(v)— use goutil'sreflects.Len(v)instead.validatetag.Previously a sub-struct field (struct /
*struct/ slice-of-struct /map-of-struct) was always descended into to collect its inner rules. Now
(
CheckSubOnParentMarkeddefaults to true) cascade only happens when theparent field has a
validatetag — the value may be empty (validate:""is enough to mark it); a named field with no
validatetag is nolonger descended into (Java
@Valid-style opt-in). Anonymous embeddedstructs (e.g.
type Bar struct { Foo }) are exempt — they are part ofthe 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.
New Features
AddCustomType(fn CustomTypeFunc, types ...any)— register an underlyingvalue 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; returningnilis treated as empty. Mirrorsgo-playground/validator's
RegisterCustomTypeFunc.ResetCustomTypes()clearsthe 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
*Validationinstances across manysame-type validations, amortizing construction cost (allocs roughly halved in
reuse scenarios). Non-default:
Struct/Map/Newbehavior and lifecycleare unchanged.
Performance
Measured on Go 1.25 (count=6) against the v1.6.0 final:
Coverage 95.7% (v1.6.0 was 95.6%).
Internal
convertArgsType).validators.goby category (compare / string / type files).fieldValueintointernal/(reflectx,fieldval).Configuration
📅 Schedule: (UTC)
🚦 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.
This PR has been generated by Renovate Bot.