feat 配置文件路径从环境变量中获取
This commit is contained in:
parent
6835f8bca4
commit
d3ead81583
@ -21,8 +21,10 @@ func main() {
|
||||
ctx := context.Background()
|
||||
_ctx, cancel := signal.NotifyContext(ctx, os.Kill, os.Interrupt)
|
||||
defer cancel()
|
||||
cfg, _ := options.LoadConfig()
|
||||
|
||||
cfg, err := options.LoadConfig()
|
||||
if err != nil {
|
||||
glog.Fatalf("获取配置失败:%v", err)
|
||||
}
|
||||
db, err := database.InitDatabase(&cfg.DB)
|
||||
if err != nil {
|
||||
glog.Fatalf("初始化数据库失败:%v", err)
|
||||
|
@ -11,8 +11,12 @@ type Config struct {
|
||||
}
|
||||
|
||||
func LoadConfig() (*Config, error) {
|
||||
cfgPath := os.Getenv("CONFIG_PATH")
|
||||
if cfgPath == "" {
|
||||
cfgPath = "/data/cfg.yaml"
|
||||
}
|
||||
var opt Config
|
||||
f, err := os.Open("/data/cfg.yaml")
|
||||
f, err := os.Open(cfgPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user