diff --git a/json_utility.go b/json_utility.go index b5a3aa9..9d437c8 100644 --- a/json_utility.go +++ b/json_utility.go @@ -1,3 +1,6 @@ +// @TODO: Be more verbose about corrupt config error. +// Do the same errror checking when doing table reloading. +// Discard previous tables when doing reload. package restutility import ( @@ -7,8 +10,10 @@ import ( "gopkg.in/rana/ora.v3" "io" "io/ioutil" + "sync" ) +var mu = &sync.Mutex{} var allPayloads []payloadBuff type LangMap map[string]map[string]string @@ -134,6 +139,8 @@ func loadCorrelations(id string) []CorrelationField { func InitTables(db *ora.Ses, project string) error { jsonbuf, _ := fetchJSON(db, EqualQuotes(project)) + mu.Lock() + defer mu.Unlock() json.Unmarshal(jsonbuf, &allPayloads) if len(allPayloads) == 0 { return errors.New("tables config is corrupt")