diff --git a/algorithms/map.go b/algorithms/map.go index b635e87..6a936ea 100644 --- a/algorithms/map.go +++ b/algorithms/map.go @@ -1,6 +1,15 @@ package algorithms -func Merge(m1, m2 map[string]interface{}) map[string]interface{} { +func Merge(maps ...map[string]interface{}) map[string]interface{} { + res := maps[0] + for _, m := range maps[1:] { + res = deepMerge(res, m) + } + + return res +} + +func deepMerge(m1, m2 map[string]interface{}) map[string]interface{} { // lifted from helm's merge code out := make(map[string]interface{}, len(m1)) for k, v := range m1 { @@ -11,7 +20,7 @@ func Merge(m1, m2 map[string]interface{}) map[string]interface{} { if v, ok := v.(map[string]interface{}); ok { if bv, ok := out[k]; ok { if bv, ok := bv.(map[string]interface{}); ok { - out[k] = Merge(bv, v) + out[k] = deepMerge(bv, v) continue } }