Some checks failed
部署后端服务 / 🚀 构建并部署 (push) Failing after 8m36s
- 修复配置文件路径错误:etc/photographyapi-api.yaml -> etc/photography-api.yaml - 修复Dockerfile未包含配置文件的问题 - 确保后端服务容器能正确加载配置文件 修复了容器启动时报'config file etc/photographyapi-api.yaml: no such file or directory'的错误
42 lines
893 B
Go
42 lines
893 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()
|
|
}
|