mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
25 lines
614 B
Go
25 lines
614 B
Go
|
package data
|
||
|
|
||
|
func MergeMaps(base, overlay map[string]interface{}) map[string]interface{} {
|
||
|
result := map[string]interface{}{}
|
||
|
for k, v := range base {
|
||
|
result[k] = v
|
||
|
}
|
||
|
for k, v := range overlay {
|
||
|
if baseMap, overlayMap, bothMaps := bothMaps(result[k], v); bothMaps {
|
||
|
v = MergeMaps(baseMap, overlayMap)
|
||
|
}
|
||
|
result[k] = v
|
||
|
}
|
||
|
return result
|
||
|
}
|
||
|
|
||
|
func bothMaps(left, right interface{}) (map[string]interface{}, map[string]interface{}, bool) {
|
||
|
leftMap, ok := left.(map[string]interface{})
|
||
|
if !ok {
|
||
|
return nil, nil, false
|
||
|
}
|
||
|
rightMap, ok := right.(map[string]interface{})
|
||
|
return leftMap, rightMap, ok
|
||
|
}
|