mirror of https://github.com/gin-gonic/gin.git
Merge pull request #224 from zazab/bind-check-sub-structs
Add validating sub structures
This commit is contained in:
commit
0f46ae2b81
|
@ -199,6 +199,22 @@ func Validate(obj interface{}, parents ...string) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fieldType := field.Type.Kind()
|
||||
if fieldType == reflect.Struct {
|
||||
if reflect.DeepEqual(zero, fieldValue) {
|
||||
continue
|
||||
}
|
||||
err := Validate(fieldValue, field.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
} else if fieldType == reflect.Slice && field.Type.Elem().Kind() == reflect.Struct {
|
||||
err := Validate(fieldValue, field.Name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
case reflect.Slice:
|
||||
|
|
Loading…
Reference in New Issue