28 lines
833 B
Go
28 lines
833 B
Go
package corecfg
|
|
|
|
// deepMerge merges dict2 into dict1 in place and returns dict1, mirroring
|
|
// corecfg_manager.py's module-level deep_merge(): nested maps recurse,
|
|
// matching lists are concatenated, everything else is overwritten by dict2.
|
|
func deepMerge(dict1, dict2 map[string]interface{}) map[string]interface{} {
|
|
for k, v := range dict2 {
|
|
existing, exists := dict1[k]
|
|
if exists {
|
|
existingMap, existingIsMap := existing.(map[string]interface{})
|
|
vMap, vIsMap := v.(map[string]interface{})
|
|
if existingIsMap && vIsMap {
|
|
dict1[k] = deepMerge(existingMap, vMap)
|
|
continue
|
|
}
|
|
|
|
existingList, existingIsList := existing.([]interface{})
|
|
vList, vIsList := v.([]interface{})
|
|
if existingIsList && vIsList {
|
|
dict1[k] = append(existingList, vList...)
|
|
continue
|
|
}
|
|
}
|
|
dict1[k] = v
|
|
}
|
|
return dict1
|
|
}
|