Skip to content

new v4 API and use Go modules

Latest
Compare
Choose a tag to compare
@rogpeppe rogpeppe released this 04 Nov 13:07
· 8 commits to v4 since this release
c9f71fb

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)