Skip to content

Releases: heetch/walidator

new v4 API and use Go modules

04 Nov 13:07
c9f71fb
Compare
Choose a tag to compare

This release change walidator to use Go modules, meaning that a new import path must be used:

import "github.com/heetch/walidator/v4"

The API has been substantially simplified and made more regular; most of the regular usage is compatible (most of the semantics of tags have not changed), but some little-used features have been removed and some other API features have been cleaned up.

New features

  • ValidationFunc has changed to a type that allows validation functions to be more efficient in parsing arguments and checking the value type. Custom validators will need to be rewritten to use this type.
  • the AddValidation method has been added, using the new ValidationFunc type. This changes the semantics of SetValidationFunc so that it can't be used to change validator names retrospectively.
  • min and max now work work on unsigned types too.
  • uuid now works on named string types
  • required now checks that maps and slices are non-nil.
  • NewValidator is renamed to New.
  • ErrorMap is renamed to Errors. The new type includes information about the validator that failed as well as the message, opening the way to including more detailed failure information without compromising the ability of callers to introspect into validation error. An Errors will always be returned if there's an error.

Removed features

  • Valid and Validator.Valid have been removed.. For a static validation string, it's always possible to use a struct value, and for a dynamic validation string, we suggest that the logic would be better written as Go code.
  • the SetValidationFunc method has been removed. Use the new AddValidation method instead.
  • make len validation fail on scalar types. Using validate:"len" on an integer or floating point value seems like it's wrong - the "length" of an integer is not its value.
  • the global Validator instance may no longer be changed (via SetTag and SetValidationFunc). This capability could easily lead to unexpected behavior when unrelated packages try to do the same thing. You can always create your own Validator instance.
  • remove ErrorArray and TextErr (see ErrorMap changes above)

v3.2.0

04 Nov 12:52
9af1182
Compare
Choose a tag to compare

This release implements substantial performance increases by refactoring the code internally.
There should be no externally visible changes, but we're tagging a new minor version anyway because of the extent of the internal changes.

Some sample speed improvement benchmarks:

        name        old time/op  new time/op  delta
        Latitude-4  3.58µs ±13%  0.27µs ± 1%  -92.32%  (p=0.016 n=5+4)
        UUID-4      23.8µs ± 5%   1.0µs ±15%  -95.85%  (p=0.008 n=5+5)
        Validate-4  13.3µs ±10%   0.6µs ± 4%  -95.27%  (p=0.008 n=5+5)

v3.1.0

28 Feb 11:56
e309c54
Compare
Choose a tag to compare
  • Add latitude and longitude tags to validate Longitude and Latitude

v3.0.0

13 Dec 15:01
c95c719
Compare
Choose a tag to compare

Improvements over https://github.com/go-validator/validator v2 branch:

  • Add jsonTagName instead of fieldName in error map #2
  • Add uuid builtin validator for validating UUID #3
  • Add required builtin validator for validating non nil pointers #4