Skip to content

Commit

Permalink
Merge pull request #224 from zazab/bind-check-sub-structs
Browse files Browse the repository at this point in the history
Add validating sub structures
  • Loading branch information
javierprovecho committed Mar 8, 2015
2 parents 1a237a8 + b537c5d commit 0f46ae2
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions binding/binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 0f46ae2

Please sign in to comment.