From f145e435c7e6648789b7be6822103901fe45a322 Mon Sep 17 00:00:00 2001 From: Evgeny Persienko Date: Fri, 20 Feb 2015 11:37:20 +0600 Subject: [PATCH 1/2] Add validating sub structures --- binding/binding.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/binding/binding.go b/binding/binding.go index 81ac3fa5..cff06f88 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -199,6 +199,17 @@ 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 + } + } } } case reflect.Slice: From b537c5d15ec87896287bfe0415d7d130244d2781 Mon Sep 17 00:00:00 2001 From: Evgeny Persienko Date: Fri, 20 Feb 2015 14:33:50 +0600 Subject: [PATCH 2/2] Add slice elements check for not required slice --- binding/binding.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/binding/binding.go b/binding/binding.go index cff06f88..1f72b63b 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -209,6 +209,11 @@ func Validate(obj interface{}, parents ...string) error { 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 + } } } }