map to anonymous field

This commit is contained in:
2025-09-25 10:00:19 +08:00
parent fd73dd9373
commit de139d0575
2 changed files with 42 additions and 16 deletions
+8 -1
View File
@@ -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