Some checks failed
部署后端服务 / 🚀 构建并部署 (push) Has been cancelled
- 修复YAML配置文件字段格式错误(大写->小写) - 修复JWT密钥未正确识别的问题 - 修复容器内配置文件路径问题,使用绝对路径/etc/photography-api.yaml - 修复迁移工具配置文件路径 - 修复Dockerfile工作目录设置 解决了'field auth.access_secret is not set'的配置错误
42 lines
894 B
Go
42 lines
894 B
Go
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"photography-backend/internal/config"
|
|
"photography-backend/internal/handler"
|
|
"photography-backend/internal/svc"
|
|
|
|
"github.com/zeromicro/go-zero/core/conf"
|
|
"github.com/zeromicro/go-zero/rest"
|
|
)
|
|
|
|
var configFile = flag.String("f", "/etc/photography-api.yaml", "the config file")
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
var c config.Config
|
|
conf.MustLoad(*configFile, &c)
|
|
|
|
server := rest.MustNewServer(c.RestConf)
|
|
defer server.Stop()
|
|
|
|
ctx := svc.NewServiceContext(c)
|
|
handler.RegisterHandlers(server, ctx)
|
|
|
|
// 添加静态文件服务
|
|
server.AddRoute(rest.Route{
|
|
Method: http.MethodGet,
|
|
Path: "/uploads/*",
|
|
Handler: func(w http.ResponseWriter, r *http.Request) {
|
|
http.StripPrefix("/uploads/", http.FileServer(http.Dir("uploads"))).ServeHTTP(w, r)
|
|
},
|
|
})
|
|
|
|
fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
|
|
server.Start()
|
|
}
|