Skip to content

Releases: go-playground/validator

Release 6.5

04 Aug 03:05
Compare
Choose a tag to compare

Minor code cleanup, no functional changes

code cleanup, ran gofmt -s -w . on code, only a few changes.

Release 6.4

04 Aug 01:38
Compare
Choose a tag to compare

Add "exists" tag

exists
Is a special tag without a validation function attached. It is used when a field
is a Pointer, Interface or Invalid and you wish to validate that it exists.
Example: want to ensure a bool exists if you define the bool as a pointer and
use exists it will ensure there is a value; couldn't use required as it would
fail when the bool was false. exists will fail is the value is a Pointer, Interface
or Invalid and is nil. (Usage: exists)

see example in issue #142 thanks @davisford

Release 5.11

04 Aug 01:37
Compare
Choose a tag to compare

Add "exists" tag

exists
Is a special tag without a validation function attached. It is used when a field
is a Pointer, Interface or Invalid and you wish to validate that it exists.
Example: want to ensure a bool exists if you define the bool as a pointer and
use exists it will ensure there is a value; couldn't use required as it would
fail when the bool was false. exists will fail is the value is a Pointer, Interface
or Invalid and is nil. (Usage: exists)

see example in issue #142 thanks @davisford

Release 6.3

02 Aug 01:02
Compare
Choose a tag to compare

Add RegisterCustomTypeFunc for easier adding of CustomTypeFunc

see example in README or here: https://github.com/bluesuncorp/validator/blob/v6/examples/custom/custom.go

thanks @johnniedoe for the pull request

Release 6.2

31 Jul 02:32
Compare
Choose a tag to compare

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

Release 6.1.1

28 Jul 02:49
Compare
Choose a tag to compare

Added new validators:

  • ip
  • ipv4
  • ipv6
  • mac

see documentation for details https://godoc.org/gopkg.in/bluesuncorp/validator.v6

Release 6.1

27 Jul 21:26
Compare
Choose a tag to compare

Updated "required" validation logic & updated invalid field type handling

updated required validator to check for a nil value for types:
slice, map, pointer, interface, channel and function.

updated traverseField to handle invalid field type.

Release 6.0.2

27 Jul 01:55
Compare
Choose a tag to compare

split our assertion functions like IsEqual, Equal, NotEqual, PanicMatches etc...
into another library https://github.com/bluesuncorp/assert so that I can use them
in other projects.

Add single Field validation example

Release 6.0.1

23 Jul 16:54
Compare
Choose a tag to compare

Updating Docs. & Benchmarks

  • update doc.go, some v5 specific notes were left.
  • Split out benchmarks into Success and Failure for more realistic numbers.
    I was validating 2 structs within the benchmarks, both a Successful and
    Failing struct which was artificially inflating the numbers.
$ go test -cpu=4 -bench=. -benchmem=true
PASS
BenchmarkFieldSuccess-4                  5000000           326 ns/op          16 B/op          1 allocs/op
BenchmarkFieldFailure-4                  5000000           327 ns/op          16 B/op          1 allocs/op
BenchmarkFieldOrTagSuccess-4              500000          2738 ns/op          20 B/op          2 allocs/op
BenchmarkFieldOrTagFailure-4             1000000          1341 ns/op         384 B/op          6 allocs/op
BenchmarkStructSimpleSuccess-4           1000000          1282 ns/op          24 B/op          3 allocs/op
BenchmarkStructSimpleFailure-4           1000000          1870 ns/op         529 B/op         11 allocs/op
BenchmarkStructSimpleSuccessParallel-4   5000000           348 ns/op          24 B/op          3 allocs/op
BenchmarkStructSimpleFailureParallel-4   2000000           807 ns/op         529 B/op         11 allocs/op
BenchmarkStructComplexSuccess-4           200000          8081 ns/op         368 B/op         30 allocs/op
BenchmarkStructComplexFailure-4           100000         12418 ns/op        2861 B/op         72 allocs/op
BenchmarkStructComplexSuccessParallel-4   500000          2249 ns/op         369 B/op         30 allocs/op
BenchmarkStructComplexFailureParallel-4   300000          5183 ns/op        2863 B/op         72 allocs/op

Release 6.0

22 Jul 01:13
Compare
Choose a tag to compare

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