重建 common_utils
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
555 B

package configLoad
import (
"github.com/spf13/viper"
"log"
"sync"
)
var defaultConfigFile = "./config.yaml"
var configByYaml *viper.Viper
var once sync.Once
func LoadConfig() *viper.Viper {
once.Do(func() {
configByYaml = loadConfigFromYaml(defaultConfigFile)
})
return configByYaml
}
func loadConfigFromYaml(path string) *viper.Viper {
//log.Printf("读取配置文件:%s", path)
vp := viper.New()
vp.SetConfigFile(path)
err := vp.ReadInConfig()
if err != nil {
log.Fatalf("Error while reading config file %s", err)
}
return vp
}