github go-playground/validator v6.2
Release 6.2

latest releases: v10.19.0, v10.18.0, v10.17.0...
8 years ago

Add Custom Field Type validation

Now if you have a type like say one that implements go's sql driver Valuer see here: https://golang.org/src/database/sql/driver/types.go?s=1210:1293#L29

You can add a custom validator for any type as long as it implements the new validator.CustomTypeFunc
see the README, I added an example usage.

This was all started with a request from @johnniedoe here #133 thanks again!

Added CustomType Benchmarks

as you can see this new functionality does not slow down the pre-existing benchmarks

$ go test -cpu=4 -bench=. -benchmem=true
PASS
BenchmarkFieldSuccess-4                      5000000           318 ns/op          16 B/op          1 allocs/op
BenchmarkFieldFailure-4                      5000000           316 ns/op          16 B/op          1 allocs/op
BenchmarkFieldCustomTypeSuccess-4            3000000           492 ns/op          32 B/op          2 allocs/op
BenchmarkFieldCustomTypeFailure-4            2000000           843 ns/op         416 B/op          6 allocs/op
BenchmarkFieldOrTagSuccess-4                  500000          2384 ns/op          20 B/op          2 allocs/op
BenchmarkFieldOrTagFailure-4                 1000000          1295 ns/op         384 B/op          6 allocs/op
BenchmarkStructSimpleSuccess-4               1000000          1175 ns/op          24 B/op          3 allocs/op
BenchmarkStructSimpleFailure-4               1000000          1822 ns/op         529 B/op         11 allocs/op
BenchmarkStructSimpleCustomTypeSuccess-4     1000000          1302 ns/op          56 B/op          5 allocs/op
BenchmarkStructSimpleCustomTypeFailure-4     1000000          1847 ns/op         577 B/op         13 allocs/op
BenchmarkStructSimpleSuccessParallel-4       5000000           339 ns/op          24 B/op          3 allocs/op
BenchmarkStructSimpleFailureParallel-4       2000000           733 ns/op         529 B/op         11 allocs/op
BenchmarkStructComplexSuccess-4               200000          7104 ns/op         368 B/op         30 allocs/op
BenchmarkStructComplexFailure-4               100000         11996 ns/op        2861 B/op         72 allocs/op
BenchmarkStructComplexSuccessParallel-4      1000000          2252 ns/op         368 B/op         30 allocs/op
BenchmarkStructComplexFailureParallel-4       300000          4691 ns/op        2862 B/op         72 allocs/op

Don't miss a new validator release

NewReleases is sending notifications on new releases.