// Package response 提供统一响应封装:{"code":200,"msg":"...","data":...}。 package response import ( "net/http" "github.com/gin-gonic/gin" ) // Body 统一响应体。 type Body struct { Code int `json:"code"` Msg string `json:"msg"` Data any `json:"data,omitempty"` } // OK 成功响应(code=200)。 func OK(c *gin.Context, data any) { c.JSON(http.StatusOK, Body{Code: 200, Msg: "ok", Data: data}) } // Fail 失败响应,httpStatus 与 code 语义一致(404 过期/不存在、403 拒绝、429 限流、500 服务端错误)。 func Fail(c *gin.Context, httpStatus int, msg string) { c.AbortWithStatusJSON(httpStatus, Body{Code: httpStatus, Msg: msg}) }