The validator package provides validation against a variable value or against the values of the fields in a struct by declaring a "tag" that instruct the engine how we want to validate the value using some built-in rules. This recipe shows how we can use this package to perform value validation.
There are 2 parts in this recipe.
main.go
- sample code of using the validator package.*_test.go
- a set of test cases that show the different validation tags - good sample code to see the extent/richness of supported validation rules that are provided by the package.
-
Run the sample code.
$ make run
-
Run (via test) to see the validation rules in action.
$ make test
-
Run both at the same time.
$ make
- Validator package
- Some formats that are supported in the validation rules.