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, group.Vars,
host.Vars, host.Vars,
} { } {
for k, v := range oVars { mapMerge(vars, oVars)
vars[k] = v
}
} }
log.Print("vars: ", vars)
return &renderContext{ return &renderContext{
Host: host, Host: host,
Group: group, Group: group,
@ -58,6 +58,19 @@ func newRenderContext(host *clustersconfig.Host, cfg *clustersconfig.Config) (ct
}, nil }, 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 { func (ctx *renderContext) Config() string {
if ctx.ConfigTemplate == nil { if ctx.ConfigTemplate == nil {
log.Fatalf("no such config: %q", ctx.Group.Config) log.Fatalf("no such config: %q", ctx.Group.Config)

View File

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