feat(conf): ones load conf

This commit is contained in:
bandl 2021-10-25 15:34:23 +08:00
parent 19562221f9
commit 06042b778c
1 changed files with 17 additions and 11 deletions

View File

@ -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() {