Add config.LookupStringMap for efficient lookups.

configurable-file-paths
Robert Gerus 2015-11-18 15:17:29 +01:00
parent b7a3b29336
commit 41bc3afc93
1 changed files with 24 additions and 0 deletions

View File

@ -145,3 +145,27 @@ func LookupStringSlice(context map[string]string, key string) (retval []string)
log.Println("Context:", context, "Key", key, "not found")
return []string{""}
}
// LookupStringMap is analogous to Lookup(), but does the cast to
// map[string]bool for optimised lookups.
func LookupStringMap(context map[string]string, key string) (retval map[string]bool) {
var value interface{}
c.l.Lock()
defer c.l.Unlock()
for _, fpath := range c.buildFileList(context) {
log.Println("Context:", context, "Looking up", key, "in", fpath)
value = lookupvar(key, fpath)
if value != nil {
log.Println("Context:", context, "Found", key, value)
for _, s := range value.([]interface{}) {
retval[s.(string)] = true
}
return retval
}
}
log.Println("Context:", context, "Key", key, "not found")
return retval
}