...
1 package main
2
3 import (
4 "fmt"
5
6 "github.com/go-playground/validator/v10"
7 )
8
9
10 type Test struct {
11 Array []string `validate:"required,gt=0,dive,required"`
12 Map map[string]string `validate:"required,gt=0,dive,keys,keymax,endkeys,required,max=1000"`
13 }
14
15
16 var validate *validator.Validate
17
18 func main() {
19
20 validate = validator.New()
21
22
23
24 validate.RegisterAlias("keymax", "max=10")
25
26 var test Test
27
28 val(test)
29
30 test.Array = []string{""}
31 test.Map = map[string]string{"test > than 10": ""}
32 val(test)
33 }
34
35 func val(test Test) {
36 fmt.Println("testing")
37 err := validate.Struct(test)
38 fmt.Println(err)
39 }
40
View as plain text