Skip to content

feat: configure the rules of the tags of go-playground/validator - #72

Merged
Insei merged 4 commits into
mainfrom
feat/tags
Oct 19, 2026
Merged

Insei merged 4 commits into
mainfrom
feat/tags

Conversation

@Insei

@Insei Insei commented Oct 19, 2026

Copy link
Copy Markdown
Owner

b.Tags("validate") in Configure applies the tags of go-playground/validator as the rules of valigo, for a migration: the structs keep their tags, the rules move to code one by one, tags and code are mixed in one Configure.

  • The same rules, messages, codes, translations and JSON Schema constraints; a valid object is validated without allocations. Bench, one run: 392 ns by the tags vs 373 ns by the same rules in code, 0 allocs; invalid 2091 vs 2113 ns, 14 allocs.
  • Strings (lengths in characters, oneof, formats, startswith..., datetime, eqfield), numbers of all kinds (min/gte, max/lte, eq, oneof, latitude, gtefield...), bool, time.Time (gtfield, ltfield), lengths of slices and maps, unique, dive into elements and values of map[string]V, omitempty, required of nested struct pointers.
  • The rules of the fields of a nil nested struct are skipped, like by go-playground/validator (shared.InStruct) — the optional address with a required city keeps working after the migration.
  • Unknown rules, |, keys, dive into structs, unique of pointer slices panic in Configure with the field and the reason: a typo isn't a missing check.

test(timex): the tests moved to timex_test, valigo imports timex now. Docs: Configuration → Rules from tags with the table of the rules and the differences from go-playground/validator; the roadmap item of the README is done. 100% coverage.

Insei added 4 commits October 19, 2026 11:42
The tests import valigo, and valigo is going to import timex for the
rules of tags: an internal test package would be an import cycle.
SetNow of export_test.go replaces the current time.
Configurator.Tags("validate") configures the rules of the tags of the
fields of the struct and of its nested structs, validate:"required,max=64",
by the rules of valigo with their messages, codes and constraints: the
rules of strings, numbers, bools, times, the lengths of slices and maps,
dive into the elements and the values of map[string]V, unique, the rules
on other fields, omitempty. The rules of the fields of a nil nested
struct are skipped, like by go-playground/validator. An unknown rule
panics in Configure. shared.InStruct reports whether the nested structs
of a field are present.
@github-actions

Copy link
Copy Markdown
Contributor

Benchmark diff: a96d717 → 4856d45 (10 runs)

goos: linux
goarch: amd64
pkg: github.com/insei/valigo
cpu: INTEL(R) XEON(R) PLATINUM 8573C
           │  base.txt   │              head.txt              │
           │   sec/op    │   sec/op     vs base               │
Validate-4   111.7n ± 1%   108.5n ± 2%  -2.78% (p=0.000 n=10)

           │  base.txt  │            head.txt            │
           │    B/op    │    B/op     vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

           │  base.txt  │            head.txt            │
           │ allocs/op  │ allocs/op   vs base            │
Validate-4   0.000 ± 0%   0.000 ± 0%  ~ (p=1.000 n=10) ¹
¹ all samples are equal

@Insei
Insei merged commit 28cb144 into main Oct 19, 2026
6 checks passed
@Insei
Insei deleted the feat/tags branch October 19, 2026 08:44
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a96d717) to head (ac4872f).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##              main       #72    +/-   ##
==========================================
  Coverage   100.00%   100.00%            
==========================================
  Files           37        38     +1     
  Lines         1250      1471   +221     
==========================================
+ Hits          1250      1471   +221     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants