瀏覽代碼

experimenting with recursive update

reid 2 年之前
父節點
當前提交
af4c94b504
共有 1 個文件被更改,包括 4 次插入0 次删除
  1. 4 0
      broadcast/broadcast.go

+ 4 - 0
broadcast/broadcast.go

@@ -285,12 +285,16 @@ func recursiveUpdate(dst, src reflect.Value) error {
 	}
 	// If both dst and src are maps, handle them recursively
 	if dst.Kind() == reflect.Map && src.Kind() == reflect.Map {
+		if dst.IsNil() {
+			dst.Set(reflect.MakeMap(dst.Type()))
+		}
 		for _, key := range src.MapKeys() {
 			srcVal := src.MapIndex(key)
 			// If the key doesn't exist in dst, initialize it
 			dstVal := dst.MapIndex(key)
 			if !dstVal.IsValid() {
 				dstVal = reflect.New(dst.Type().Elem()).Elem()
+				dst.SetMapIndex(key, dstVal)  // Set the new value directly into the map
 			}
 			// Recursive call to handle potential nested maps or structs
 			if err := recursiveUpdate(dstVal, srcVal); err != nil {