From 06042b778cb56df1cd0239bab12b640acf98e57e Mon Sep 17 00:00:00 2001 From: bandl <1658002533@qq.com> Date: Mon, 25 Oct 2021 15:34:23 +0800 Subject: [PATCH] feat(conf): ones load conf --- conf/public_conf.go | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) 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() {