Переглянути джерело

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 {