package myvalidator import ( "fmt" "testing" ) func TestValidate(t *testing.T) { type St struct { Id int `validate:"gte=0,lte=500"` Name string `validate:"required"` } values := []*St{ { Id: 5, Name: "name5", }, { Id: 100, Name: "", }, { Id: 600, Name: "name600", }, { Id: -1, Name: "", }, } Init() for _, v := range values { err := Verify(v) if err != nil { fmt.Println(err) } err = VerifyTrans(v) if err != nil { fmt.Println(err) } fmt.Printf("%+v\n\n", v) } }