aboutsummaryrefslogtreecommitdiff
path: root/weed/util/config.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-01-12 02:28:13 -0800
committerChris Lu <chris.lu@gmail.com>2021-01-12 02:28:13 -0800
commitcfb9342a15ce73c1e04c0e690cf87f65133bcf1b (patch)
tree40e68e68d98472e8f942c04a501839a0135ef1c5 /weed/util/config.go
parent38d516251eb080e56ee16747684e808a06cb6702 (diff)
downloadseaweedfs-cfb9342a15ce73c1e04c0e690cf87f65133bcf1b.tar.xz
seaweedfs-cfb9342a15ce73c1e04c0e690cf87f65133bcf1b.zip
avoid concurrent map updates to viper
Diffstat (limited to 'weed/util/config.go')
-rw-r--r--weed/util/config.go18
1 files changed, 15 insertions, 3 deletions
diff --git a/weed/util/config.go b/weed/util/config.go
index 94e621e34..54edf5a3c 100644
--- a/weed/util/config.go
+++ b/weed/util/config.go
@@ -2,6 +2,7 @@ package util
import (
"strings"
+ "sync"
"github.com/spf13/viper"
@@ -46,9 +47,20 @@ func LoadConfiguration(configFileName string, required bool) (loaded bool) {
return true
}
-func GetViper() *viper.Viper {
- v := &viper.Viper{}
- *v = *viper.GetViper()
+type ViperProxy struct {
+ *viper.Viper
+ sync.Mutex
+}
+
+func (vp *ViperProxy) SetDefault(key string, value interface{}) {
+ vp.Lock()
+ defer vp.Unlock()
+ vp.Viper.SetDefault(key, value)
+}
+
+func GetViper() *ViperProxy {
+ v := &ViperProxy{}
+ v.Viper = viper.GetViper()
v.AutomaticEnv()
v.SetEnvPrefix("weed")
v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))