aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-01-13 13:20:33 -0800
committerChris Lu <chris.lu@gmail.com>2021-01-13 13:20:33 -0800
commite2c7e3fe6d44c183731bf67eb5eb27f4acfe802c (patch)
tree17f74be07375632e17a106bb9e0d7c7164ef67f3
parent819a85f59aad5f8e1e8a46f9bba705cb31db7af5 (diff)
downloadseaweedfs-e2c7e3fe6d44c183731bf67eb5eb27f4acfe802c.tar.xz
seaweedfs-e2c7e3fe6d44c183731bf67eb5eb27f4acfe802c.zip
better locks
-rw-r--r--weed/util/config.go21
1 files changed, 15 insertions, 6 deletions
diff --git a/weed/util/config.go b/weed/util/config.go
index e746b0bd1..2af1ad09e 100644
--- a/weed/util/config.go
+++ b/weed/util/config.go
@@ -52,6 +52,10 @@ type ViperProxy struct {
sync.Mutex
}
+var (
+ vp = &ViperProxy{}
+)
+
func (vp *ViperProxy) SetDefault(key string, value interface{}) {
vp.Lock()
defer vp.Unlock()
@@ -83,10 +87,15 @@ func (vp *ViperProxy) GetStringSlice(key string) []string {
}
func GetViper() *ViperProxy {
- v := &ViperProxy{}
- v.Viper = viper.GetViper()
- v.AutomaticEnv()
- v.SetEnvPrefix("weed")
- v.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
- return v
+ vp.Lock()
+ defer vp.Unlock()
+
+ if vp.Viper == nil {
+ vp.Viper = viper.GetViper()
+ vp.AutomaticEnv()
+ vp.SetEnvPrefix("weed")
+ vp.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
+ }
+
+ return vp
}