fix(server): 添加YMT DSN检查并支持动态端口配置
当YMT DSN为空时跳过迁移 从环境变量读取端口号,默认使用8080
This commit is contained in:
parent
7bc0c54e1d
commit
20aa051af4
|
|
@ -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())
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue