feat: migrate to golang
This commit is contained in:
27
internal/corecfg/merge.go
Normal file
27
internal/corecfg/merge.go
Normal file
@ -0,0 +1,27 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user