forked from p93542168/wheat-cache
feat(conf): ones load conf
This commit is contained in:
parent
19562221f9
commit
06042b778c
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue