Synchronize access to configuration

configurable-file-paths
Robert Gerus 2015-11-11 21:50:38 +01:00
parent 6c77cdf7f7
commit a8c3f404aa
1 changed files with 5 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"log"
"os"
"sync"
"time"
)
@ -16,6 +17,7 @@ type cacheEntry struct {
type config struct {
cache map[string]cacheEntry
buildFileList func(map[string]string) []string
l sync.Mutex
}
var c config
@ -73,6 +75,9 @@ func SetFileListBuilder(f func(map[string]string) []string) {
func Lookup(context map[string]string, key string) interface{} {
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)