Validator returns only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it’s not check if error is InvalidValidationError ( if necessary, most of the time it isn’t ) type cast it to type ValidationErrors like so:
Here is a list of software that complements using this library either pre or post validation.
form - Decodes url.Values into Go value(s) and Encodes Go value(s) into url.Values. Dual Array and Full map support.
mold - A general library to help modify or set data within data structures and other objects
How to Contribute
Make a pull request…
License
Distributed under MIT License, please see license file within the code for more details.
Maintainers
This project has grown large enough that more than one person is required to properly support the community.
If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn
Package validator
Package validator implements value validations for structs and individual fields based on tags.
It has the following unique features:
Installation
Use go get.
Then import the validator package into your own code.
Error Return Value
Validation functions return type error
They return type error to avoid the issue discussed in the following, where err is always != nil:
Validator returns only InvalidValidationError for bad validation input, nil or ValidationErrors as type error; so, in your code all you need to do is check if the error returned is not nil, and if it’s not check if error is InvalidValidationError ( if necessary, most of the time it isn’t ) type cast it to type ValidationErrors like so:
Usage and documentation
Please see https://pkg.go.dev/github.com/go-playground/validator/v10 for detailed usage docs.
Examples:
Baked-in Validations
Fields:
Network:
Strings:
Format:
Comparisons:
Other:
Aliases:
Benchmarks
Run on MacBook Pro (15-inch, 2017) go version go1.10.2 darwin/amd64
Complementary Software
Here is a list of software that complements using this library either pre or post validation.
How to Contribute
Make a pull request…
License
Distributed under MIT License, please see license file within the code for more details.
Maintainers
This project has grown large enough that more than one person is required to properly support the community. If you are interested in becoming a maintainer please reach out to me https://github.com/deankarn