feat(kontemplate): defaults can now have nested values
See https://b.tvl.fyi/issues/409 for details. Change-Id: Ibb54fab7a78e0e5f708c2a7dc8bb26ac0b2b4689 Signed-off-by: Armin Schlegel <a.schlegel@gridx.de> Reviewed-on: https://cl.tvl.fyi/c/depot/+/11972 Tested-by: BuildkiteCI Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
parent
2beabe968c
commit
2357079891
2 changed files with 23 additions and 1 deletions
|
|
@ -29,13 +29,29 @@ func Merge(in1 *map[string]interface{}, in2 *map[string]interface{}) *map[string
|
|||
return in1
|
||||
}
|
||||
|
||||
// The maps are map[string]interface{} with unknown depth.
|
||||
// Loop over both maps into every level and merge them.
|
||||
new := make(map[string]interface{})
|
||||
|
||||
for k, v := range *in1 {
|
||||
new[k] = v
|
||||
}
|
||||
|
||||
for k, v := range *in2 {
|
||||
new[k] = v
|
||||
if existing, ok := new[k]; ok {
|
||||
// If both values are maps, merge them recursively
|
||||
if existingMap, ok := existing.(map[string]interface{}); ok {
|
||||
if newMap, ok := v.(map[string]interface{}); ok {
|
||||
new[k] = *Merge(&existingMap, &newMap)
|
||||
} else {
|
||||
new[k] = v
|
||||
}
|
||||
} else {
|
||||
new[k] = v
|
||||
}
|
||||
} else {
|
||||
new[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return &new
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue