From 20aa051af44a8a933b96bf2b5dd114f4458688c3 Mon Sep 17 00:00:00 2001 From: zhouyonggao <1971162852@qq.com> Date: Mon, 24 Nov 2025 17:46:28 +0800 Subject: [PATCH] =?UTF-8?q?fix(server):=20=E6=B7=BB=E5=8A=A0YMT=20DSN?= =?UTF-8?q?=E6=A3=80=E6=9F=A5=E5=B9=B6=E6=94=AF=E6=8C=81=E5=8A=A8=E6=80=81?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 当YMT DSN为空时跳过迁移 从环境变量读取端口号,默认使用8080 --- server/cmd/server/main.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/server/cmd/server/main.go b/server/cmd/server/main.go index b59547a..ebb5bc7 100644 --- a/server/cmd/server/main.go +++ b/server/cmd/server/main.go @@ -33,12 +33,17 @@ func main() { if err != nil { log.Fatal(err) } - if err := migrate.Apply(ymt); err != nil { - log.Fatal(err) + if ymtDSN != "" { + if err := migrate.Apply(ymt); err != nil { + log.Fatal(err) + } + } else { + log.Println("skip migrations: YMT DSN missing") } r := api.NewRouter(ymt, marketing) - srv := &http.Server{Addr: ":8080", Handler: r, ReadTimeout: 15 * time.Second, WriteTimeout: 60 * time.Second} - log.Println("server listening on :8080") + addr := ":" + func() string { s := os.Getenv("PORT"); if s == "" { return "8080" }; return s }() + srv := &http.Server{Addr: addr, Handler: r, ReadTimeout: 15 * time.Second, WriteTimeout: 60 * time.Second} + log.Println("server listening on ", addr) log.Fatal(srv.ListenAndServe()) }