map to anonymous field
This commit is contained in:
@@ -176,7 +176,8 @@ func copyStruct2Map(dst, src reflect.Value, depth int, fieldName string, opt *op
|
||||
func copyMap2Struct(dst, src reflect.Value, depth int, _ string, opt *options) error {
|
||||
// 循环结构,然后从map取值
|
||||
typ := dst.Type()
|
||||
for i := 0; i < dst.NumField(); i++ {
|
||||
|
||||
for i, n := 0, src.NumField(); i < n; i++ {
|
||||
field := dst.Field(i)
|
||||
sf := typ.Field(i)
|
||||
|
||||
@@ -184,6 +185,12 @@ func copyMap2Struct(dst, src reflect.Value, depth int, _ string, opt *options) e
|
||||
continue
|
||||
}
|
||||
|
||||
if sf.Anonymous {
|
||||
if err := deepCopy(field, src, depth+1, sf.Name, opt); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
name := getFieldName(sf)
|
||||
if name == "-" {
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user