From 0569c5fb95a49ce4b9a7cc7bc3bad3ee3e152da8 Mon Sep 17 00:00:00 2001 From: Martin Karlsch Date: Fri, 27 Mar 2015 08:31:27 -0700 Subject: [PATCH] add support for embedded struct to Bind --- binding/binding.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/binding/binding.go b/binding/binding.go index 752c9129..87a100b0 100644 --- a/binding/binding.go +++ b/binding/binding.go @@ -84,6 +84,17 @@ func mapForm(ptr interface{}, form map[string][]string) error { formStruct := reflect.ValueOf(ptr).Elem() for i := 0; i < typ.NumField(); i++ { typeField := typ.Field(i) + + // support for embeded fields + valueField := formStruct.Field(i) + if valueField.Kind() == reflect.Struct { + err := mapForm(valueField.Addr().Interface(), form) + if err != nil { + return err + } + continue + } + if inputFieldName := typeField.Tag.Get("form"); inputFieldName != "" { structField := formStruct.Field(i) if !structField.CanSet() {