github go-playground/validator v6.0
Release 6.0

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

And the long awaited v6 is here!

Highlights

  • Code has been completely refactored for simplicity, maintenance, speed, efficiency and is DRY
  • validator.New now accepts a config struct to allow for adding of new param and keep backward compatibility
  • Hierarchy error structure has been removed both validate "Field" and "Struct" now returns ValidationErrors which is really a map[string]*FieldError, but had to type it so ValidationErrors can be used as a regular error type.
  • Func ( validation funcs ) have been updated to the following input params (topStruct reflect.Value, currentStruct reflect.Value, field reflect.Value, fieldType reflect.Type, fieldKind reflect.Kind, param string) was already getting the reflect Value, so why pass it around by interface just to look at the value all over again.
  • When validating a struct the Struct Name is prepended to the error key i.e. Struct User and Field Name the error key will be "User.Name"
  • v6 is intended to be a long term stable release and only additions to validation functions.

Benchmarks

$ go test -cpu=4 -bench=. -benchmem=true
PASS
BenchmarkField-4                     5000000           316 ns/op          16 B/op          1 allocs/op
BenchmarkFieldOrTag-4                 500000          2437 ns/op          20 B/op          2 allocs/op
BenchmarkStructSimple-4               500000          3101 ns/op         553 B/op         14 allocs/op
BenchmarkStructSimpleParallel-4      1000000          1140 ns/op         553 B/op         14 allocs/op
BenchmarkStructComplex-4              100000         19519 ns/op        3230 B/op        102 allocs/op
BenchmarkStructComplexParallel-4      200000          6681 ns/op        3232 B/op        102 allocs/op

Don't miss a new validator release

NewReleases is sending notifications on new releases.