From d3ead8158365d34d0c5537fe793330da6808a026 Mon Sep 17 00:00:00 2001 From: timerzz Date: Fri, 12 Apr 2024 14:51:51 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E4=BB=8E=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= =?UTF-8?q?=E4=B8=AD=E8=8E=B7=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main/main.go | 6 ++++-- pkg/options/init.go | 6 +++++- 2 files changed, 9 insertions(+), 3 deletions(-) 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 }