better map merge

This commit is contained in:
Mikaël Cluseau 2019-04-19 17:07:22 +01:00
parent a1fcd4093c
commit ee2779cc9d
2 changed files with 17 additions and 4 deletions

View File

@ -41,11 +41,11 @@ func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ct
group.Vars,
host.Vars,
} {
for k, v := range oVars {
vars[k] = v
}
mapMerge(vars, oVars)
}
log.Print("vars: ", vars)
return &renderContext{
Host: host,
Group: group,
@ -58,6 +58,19 @@ func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ct
}, nil
}
func mapMerge(target, source map[string]interface{}) {
for k, v := range source {
if tMap, targetIsMap := target[k].(map[string]interface{}); targetIsMap {
if sMap, sourceIsMap := v.(map[string]interface{}); sourceIsMap {
mapMerge(tMap, sMap)
continue
}
}
target[k] = v
}
}
func (ctx *renderContext) Config() string {
if ctx.ConfigTemplate == nil {
log.Fatalf("no such config: %q", ctx.Group.Config)

View File

@ -12,7 +12,7 @@ import (
)
func registerWS(rest *restful.Container) {
// Admin API
// Admin-level APIs
ws := &restful.WebService{}
ws.Filter(adminAuth).
HeaderParameter("Authorization", "Admin bearer token")