Added nil check for embedded structs

This commit is contained in:
Jimmy Pettersson 2014-08-22 15:32:41 +02:00
parent 45fcd18064
commit 06e9f94970
1 changed files with 4 additions and 0 deletions

View File

@ -176,6 +176,10 @@ func Validate(obj interface{}) error {
if strings.Index(field.Tag.Get("binding"), "required") > -1 {
fieldType := field.Type.Kind()
if fieldType == reflect.Struct {
if reflect.DeepEqual(zero, fieldValue) {
return errors.New("Required " + field.Name)
}
err := Validate(fieldValue)
if err != nil {
return err