mirror of
https://github.com/rancher/os.git
synced 2025-09-01 06:40:31 +00:00
Reliably merge the yaml maps data
This commit is contained in:
18
util/util.go
18
util/util.go
@@ -164,3 +164,21 @@ func Convert(from, to interface{}) error {
|
||||
|
||||
return yaml.Unmarshal(bytes, to)
|
||||
}
|
||||
|
||||
func MergeMaps(left, right map[interface{}]interface{}) {
|
||||
for k, v := range right {
|
||||
merged := false
|
||||
if existing, ok := left[k]; ok {
|
||||
if rightMap, ok := v.(map[interface{}]interface{}); ok {
|
||||
if leftMap, ok := existing.(map[interface{}]interface{}); ok {
|
||||
merged = true
|
||||
MergeMaps(leftMap, rightMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !merged {
|
||||
left[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user