All checks were successful
部署后端服务 / 🚀 构建并部署 (push) Successful in 1m55s
- 在后端处理程序中添加了新的健康检查路由`/health` - 该路由用于支持Caddy等反向代理的健康检查功能 此更改增强了服务的可监控性和可靠性。
179 lines
3.8 KiB
Go
179 lines
3.8 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
||
// goctl 1.8.4
|
||
|
||
package handler
|
||
|
||
import (
|
||
"net/http"
|
||
|
||
auth "photography-backend/internal/handler/auth"
|
||
category "photography-backend/internal/handler/category"
|
||
health "photography-backend/internal/handler/health"
|
||
photo "photography-backend/internal/handler/photo"
|
||
user "photography-backend/internal/handler/user"
|
||
"photography-backend/internal/svc"
|
||
|
||
"github.com/zeromicro/go-zero/rest"
|
||
)
|
||
|
||
func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 用户登录
|
||
Method: http.MethodPost,
|
||
Path: "/login",
|
||
Handler: auth.LoginHandler(serverCtx),
|
||
},
|
||
{
|
||
// 用户注册
|
||
Method: http.MethodPost,
|
||
Path: "/register",
|
||
Handler: auth.RegisterHandler(serverCtx),
|
||
},
|
||
},
|
||
rest.WithPrefix("/api/v1/auth"),
|
||
)
|
||
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 获取分类列表
|
||
Method: http.MethodGet,
|
||
Path: "/",
|
||
Handler: category.GetCategoryListHandler(serverCtx),
|
||
},
|
||
{
|
||
// 创建分类
|
||
Method: http.MethodPost,
|
||
Path: "/",
|
||
Handler: category.CreateCategoryHandler(serverCtx),
|
||
},
|
||
{
|
||
// 获取分类详情
|
||
Method: http.MethodGet,
|
||
Path: "/:id",
|
||
Handler: category.GetCategoryHandler(serverCtx),
|
||
},
|
||
{
|
||
// 更新分类
|
||
Method: http.MethodPut,
|
||
Path: "/:id",
|
||
Handler: category.UpdateCategoryHandler(serverCtx),
|
||
},
|
||
{
|
||
// 删除分类
|
||
Method: http.MethodDelete,
|
||
Path: "/:id",
|
||
Handler: category.DeleteCategoryHandler(serverCtx),
|
||
},
|
||
},
|
||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||
rest.WithPrefix("/api/v1/categories"),
|
||
)
|
||
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 健康检查
|
||
Method: http.MethodGet,
|
||
Path: "/health",
|
||
Handler: health.HealthHandler(serverCtx),
|
||
},
|
||
},
|
||
rest.WithPrefix("/api/v1"),
|
||
)
|
||
|
||
// 额外的根路径健康检查,用于Caddy等反向代理
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 根路径健康检查
|
||
Method: http.MethodGet,
|
||
Path: "/health",
|
||
Handler: health.HealthHandler(serverCtx),
|
||
},
|
||
},
|
||
)
|
||
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 获取照片列表
|
||
Method: http.MethodGet,
|
||
Path: "/",
|
||
Handler: photo.GetPhotoListHandler(serverCtx),
|
||
},
|
||
{
|
||
// 上传照片
|
||
Method: http.MethodPost,
|
||
Path: "/",
|
||
Handler: photo.UploadPhotoHandler(serverCtx),
|
||
},
|
||
{
|
||
// 获取照片详情
|
||
Method: http.MethodGet,
|
||
Path: "/:id",
|
||
Handler: photo.GetPhotoHandler(serverCtx),
|
||
},
|
||
{
|
||
// 更新照片
|
||
Method: http.MethodPut,
|
||
Path: "/:id",
|
||
Handler: photo.UpdatePhotoHandler(serverCtx),
|
||
},
|
||
{
|
||
// 删除照片
|
||
Method: http.MethodDelete,
|
||
Path: "/:id",
|
||
Handler: photo.DeletePhotoHandler(serverCtx),
|
||
},
|
||
},
|
||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||
rest.WithPrefix("/api/v1/photos"),
|
||
)
|
||
|
||
server.AddRoutes(
|
||
[]rest.Route{
|
||
{
|
||
// 获取用户列表
|
||
Method: http.MethodGet,
|
||
Path: "/",
|
||
Handler: user.GetUserListHandler(serverCtx),
|
||
},
|
||
{
|
||
// 创建用户
|
||
Method: http.MethodPost,
|
||
Path: "/",
|
||
Handler: user.CreateUserHandler(serverCtx),
|
||
},
|
||
{
|
||
// 获取用户详情
|
||
Method: http.MethodGet,
|
||
Path: "/:id",
|
||
Handler: user.GetUserHandler(serverCtx),
|
||
},
|
||
{
|
||
// 更新用户
|
||
Method: http.MethodPut,
|
||
Path: "/:id",
|
||
Handler: user.UpdateUserHandler(serverCtx),
|
||
},
|
||
{
|
||
// 删除用户
|
||
Method: http.MethodDelete,
|
||
Path: "/:id",
|
||
Handler: user.DeleteUserHandler(serverCtx),
|
||
},
|
||
{
|
||
// 上传用户头像
|
||
Method: http.MethodPost,
|
||
Path: "/:id/avatar",
|
||
Handler: user.UploadAvatarHandler(serverCtx),
|
||
},
|
||
},
|
||
rest.WithJwt(serverCtx.Config.Auth.AccessSecret),
|
||
rest.WithPrefix("/api/v1/users"),
|
||
)
|
||
}
|