1 Star 0 Fork 0

颜圭源 / nt-cm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
config.go 557 Bytes
一键复制 编辑 原始数据 按行查看 历史
颜圭源 提交于 2023-07-14 23:01 . v1.0.2
package config
import (
"flag"
"fmt"
"github.com/spf13/viper"
"os"
)
func NewConfig() *viper.Viper {
envConf := os.Getenv("APP_CONF")
if envConf == "" {
flag.StringVar(&envConf, "conf", "config/local.yml", "config path, eg: -conf config/local.yml")
flag.Parse()
}
if envConf == "" {
envConf = "local"
}
fmt.Println("load conf file:", envConf)
return GetConfig(envConf)
}
func GetConfig(path string) *viper.Viper {
conf := viper.New()
conf.SetConfigFile(path)
err := conf.ReadInConfig()
if err != nil {
panic(err)
}
return conf
}
Go
1
https://gitee.com/yan-guiyuan/nt-cm.git
git@gitee.com:yan-guiyuan/nt-cm.git
yan-guiyuan
nt-cm
nt-cm
669857172933

搜索帮助