6 // "gopkg.in/go-playground/validator.v8"
9 // func ExampleValidate_new() {
10 // config := &validator.Config{TagName: "validate"}
12 // validator.New(config)
15 // func ExampleValidate_field() {
16 // // This should be stored somewhere globally
17 // var validate *validator.Validate
19 // config := &validator.Config{TagName: "validate"}
21 // validate = validator.New(config)
24 // errs := validate.Field(i, "gt=1,lte=10")
25 // err := errs.(validator.ValidationErrors)[""]
26 // fmt.Println(err.Field)
27 // fmt.Println(err.Tag)
28 // fmt.Println(err.Kind) // NOTE: Kind and Type can be different i.e. time Kind=struct and Type=time.Time
29 // fmt.Println(err.Type)
30 // fmt.Println(err.Param)
31 // fmt.Println(err.Value)
41 // func ExampleValidate_struct() {
42 // // This should be stored somewhere globally
43 // var validate *validator.Validate
45 // config := &validator.Config{TagName: "validate"}
47 // validate = validator.New(config)
49 // type ContactInformation struct {
50 // Phone string `validate:"required"`
51 // Street string `validate:"required"`
52 // City string `validate:"required"`
56 // Name string `validate:"required,excludesall=!@#$%^&*()_+-=:;?/0x2C"` // 0x2C = comma (,)
57 // Age int8 `validate:"required,gt=0,lt=150"`
58 // Email string `validate:"email"`
59 // ContactInformation []*ContactInformation
62 // contactInfo := &ContactInformation{
63 // Street: "26 Here Blvd.",
68 // Name: "Joey Bloggs",
70 // Email: "joeybloggs@gmail.com",
71 // ContactInformation: []*ContactInformation{contactInfo},
74 // errs := validate.Struct(user)
75 // for _, v := range errs.(validator.ValidationErrors) {
76 // fmt.Println(v.Field) // Phone
77 // fmt.Println(v.Tag) // required