diff options
| author | Yoni Nakache <45972051+LazyDBA247-Anyvision@users.noreply.github.com> | 2021-01-13 22:32:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-13 22:32:23 +0200 |
| commit | d1959de03894fb77753be622f18ec70e0a45eb43 (patch) | |
| tree | 31bc579b3c780dc6ce3e412b892da246fefa6d1a /weed/util/config.go | |
| parent | 95982e0856dcde5cd7542532367c436503d39a7a (diff) | |
| parent | 3fb2ed90932f608b3fd8e9c29d32663b7402e8eb (diff) | |
| download | seaweedfs-d1959de03894fb77753be622f18ec70e0a45eb43.tar.xz seaweedfs-d1959de03894fb77753be622f18ec70e0a45eb43.zip | |
Merge branch 'master' into master
Diffstat (limited to 'weed/util/config.go')
| -rw-r--r-- | weed/util/config.go | 18 |
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(".", "_")) |
