package main
import (
"fmt"
govalidator "github.com/asaskevich/govalidator"
)
type Deep1 struct {
Deep1Val Deep2 `json:"deep_1_val" valid:"required"`
}
type Deep2 struct {
Deep2Vals []Deep3 `json:"deep_2_vals" valid:"required"`
}
type Deep3 struct {
Name string `json:"name" valid:"required~must set deep3.name"`
}
func main() {
dp2 := Deep2{
Deep2Vals: []Deep3{
{Name: ""},
},
}
dp1 := Deep1{
Deep1Val: dp2,
}
fmt.Println(govalidator.ValidateStruct(&dp2))
fmt.Println(govalidator.ValidateStruct(&dp1))
}
// if we define a struct with a Deep1 field and set valid tag, it will print error info three times when validate it
// output:
//false must set deep3.name
//false must set deep3.name;must set deep3.name
Hello guys!
I forked this package cause owner disappeared. Hope, he will be back, but it would be easier to merge these changes back if he is back
Link to my repo: create issue there and we'll discuss it.
the struct type with a valid tag was validated here , https://github.com/asaskevich/govalidator/blob/f9ffefc3facfbe0caee3fea233cbb6e8208f4541/validator.go#L767
but it would be validated here another time. https://github.com/asaskevich/govalidator/blob/f9ffefc3facfbe0caee3fea233cbb6e8208f4541/validator.go#L1205
for example:
how about change this line to "return true,nil"? https://github.com/asaskevich/govalidator/blob/f9ffefc3facfbe0caee3fea233cbb6e8208f4541/validator.go#L1205