Explorar o código

experimenting with recursive update

reid %!s(int64=2) %!d(string=hai) anos
pai
achega
af4c94b504
Modificáronse 1 ficheiros con 4 adicións e 0 borrados
  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 {