From 78f2fd8d146e3bfdd2a67420a51683e56e6069c0 Mon Sep 17 00:00:00 2001 From: Xingang Zhang <0x0400@users.noreply.github.com> Date: Sat, 21 Jul 2018 14:56:09 +0800 Subject: [PATCH] acquire lock when access config data --- config/yaml/yaml.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/config/yaml/yaml.go b/config/yaml/yaml.go index 2fbb027c..881737e3 100644 --- a/config/yaml/yaml.go +++ b/config/yaml/yaml.go @@ -119,7 +119,7 @@ func parseYML(buf []byte) (cnf map[string]interface{}, err error) { // ConfigContainer A Config represents the yaml configuration. type ConfigContainer struct { data map[string]interface{} - sync.Mutex + sync.RWMutex } // Bool returns the boolean value for a given key. @@ -285,6 +285,9 @@ func (c *ConfigContainer) getData(key string) (interface{}, error) { if len(key) == 0 { return nil, errors.New("key is empty") } + c.RLock() + defer c.RUnlock() + keys := strings.Split(key, ".") tmpData := c.data for _, k := range keys {