Merge pull request #224 from zazab/bind-check-sub-structs

Add validating sub structures
This commit is contained in:
Javier Provecho Fernandez 2015-03-08 14:33:22 +01:00
commit 0f46ae2b81

View File

@ -199,6 +199,22 @@ func Validate(obj interface{}, parents ...string) error {
return err 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: case reflect.Slice: