diff --git a/conf/public_conf.go b/conf/public_conf.go index 533b64a..d5f0791 100644 --- a/conf/public_conf.go +++ b/conf/public_conf.go @@ -2,6 +2,7 @@ package conf import ( "log" + "sync" "github.com/spf13/viper" ) @@ -10,18 +11,23 @@ const ( linuxPath = "/etc/wheat-cache/" ) -func init() { - setDefaultConfValue() - err := LoadConf("") - switch err.(type) { - case nil: - case viper.ConfigFileNotFoundError: - formatPath := []string{linuxPath} - log.Fatalf("the profile could not be read, read path:%v", formatPath) - default: - log.Fatalf("the resolution of the profile failed, err: %v", err) +var confLock sync.Once - } +func init() { + confLock.Do(func() { + setDefaultConfValue() + err := LoadConf("") + switch err.(type) { + case nil: + case viper.ConfigFileNotFoundError: + formatPath := []string{linuxPath} + log.Fatalf("the profile could not be read, read path:%v", formatPath) + default: + log.Fatalf("the resolution of the profile failed, err: %v", err) + + } + }, + ) } func setDefaultConfValue() {