diff --git a/main/main.go b/main/main.go index 5c021a9..5f00850 100644 --- a/main/main.go +++ b/main/main.go @@ -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) diff --git a/pkg/options/init.go b/pkg/options/init.go index b716fd6..1f2c157 100644 --- a/pkg/options/init.go +++ b/pkg/options/init.go @@ -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 }