Synchronize access to configuration
parent
6c77cdf7f7
commit
a8c3f404aa
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue