Skip to content

Latest commit

 

History

History

validation

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

Validation

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.

Setup

  1. Run the sample code.

    $ make run
  2. Run (via test) to see the validation rules in action.

    $ make test
  3. Run both at the same time.

    $ make

Reference