add support for embedded struct to Bind
This commit is contained in:
parent
e2fa89777e
commit
0569c5fb95
@ -84,6 +84,17 @@ func mapForm(ptr interface{}, form map[string][]string) error {
|
|||||||
formStruct := reflect.ValueOf(ptr).Elem()
|
formStruct := reflect.ValueOf(ptr).Elem()
|
||||||
for i := 0; i < typ.NumField(); i++ {
|
for i := 0; i < typ.NumField(); i++ {
|
||||||
typeField := typ.Field(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 != "" {
|
if inputFieldName := typeField.Tag.Get("form"); inputFieldName != "" {
|
||||||
structField := formStruct.Field(i)
|
structField := formStruct.Field(i)
|
||||||
if !structField.CanSet() {
|
if !structField.CanSet() {
|
||||||
|
Loading…
Reference in New Issue
Block a user