补齐 HTTP 层:实现用户模块、路由与中间件接线、COS 上传及优雅启动
- 新增用户与上传错误码文件及 Recovery 中间件 - 修复 router.go 导入与中间件链,注册用户路由并补 handler 错误码导入 - 补充用户状态常量与 UserGetByWechatOpenID 查询,修订刷新令牌 dto - 移除 upload 包 OTel 调用,新增 FileUploadCos 上传封装 - 实现 UserService 微信登录/刷新令牌/我的信息/改资料/上传头像 - 裁剪 main.go 配置段并移除 OTel 桥接,补启动与优雅退出 - 新增 configs 示例配置、global 配置结构及 go.mod 依赖
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"git.lzcwy.cn/zhengchiliu/zt-online-game-backend/pkg/errcode"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
// Response 统一响应包装
|
||||
type Response struct {
|
||||
Ctx *gin.Context
|
||||
}
|
||||
|
||||
func NewResponse(c *gin.Context) *Response {
|
||||
return &Response{Ctx: c}
|
||||
}
|
||||
|
||||
// ToResponse 成功响应
|
||||
func (r *Response) ToResponse(data interface{}) {
|
||||
if data == nil {
|
||||
data = gin.H{}
|
||||
}
|
||||
r.Ctx.JSON(http.StatusOK, gin.H{
|
||||
"code": errcode.Success.Code(),
|
||||
"msg": errcode.Success.Msg(),
|
||||
"data": data,
|
||||
})
|
||||
}
|
||||
|
||||
// ToErrorResponse 错误响应
|
||||
func (r *Response) ToErrorResponse(err *errcode.Error) {
|
||||
response := gin.H{
|
||||
"code": err.Code(),
|
||||
"msg": err.Msg(),
|
||||
}
|
||||
if details := err.Details(); len(details) > 0 {
|
||||
response["details"] = details
|
||||
}
|
||||
r.Ctx.JSON(err.StatusCode(), response)
|
||||
}
|
||||
Reference in New Issue
Block a user