Skip to content
Myr

Added reference to parent structs

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jimmy Pettersson · committed by Jimmy Pettersson · parent 06e9f94 · Browse files · 1 file+7 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+7 added−4 removed

  • other:+7 added−4 removed

1 file+7 added−4 removed

modified:binding/binding.go+7 added-4 removed
149 unmodified lines
150 panic("Pointers are not accepted as binding models")151 }152}153154func Validate(obj interface{}) error {154func Validate(obj interface{}, parents ...string) error {155 typ := reflect.TypeOf(obj)156 val := reflect.ValueOf(obj)157158 if typ.Kind() == reflect.Ptr {
19 unmodified lines
178 if fieldType == reflect.Struct {179 if reflect.DeepEqual(zero, fieldValue) {180 return errors.New("Required " + field.Name)181 }182183 err := Validate(fieldValue)182 err := Validate(fieldValue, field.Name)183 if err != nil {184 return err185 }186 } else if reflect.DeepEqual(zero, fieldValue) {187 if len(parents) > 0 {188 return errors.New("Required " + field.Name + " on " + parents[0])189 } else {188 return errors.New("Required " + field.Name)190 return errors.New("Required " + field.Name)191 }192 } else if fieldType == reflect.Slice && field.Type.Elem().Kind() == reflect.Struct {193 err := Validate(fieldValue)194 if err != nil {195 return err
17 unmodified lines