package response import ( "net/http" "github.com/gin-gonic/gin" ) type Result struct { Ctx *gin.Context } type BaseResponse struct { Code int `json:"code"` Message string `json:"message"` } func NewResult(ctx *gin.Context) *Result { return &Result{Ctx: ctx} } // 统一出错信息 func (r *Result) Error(code int, msg string) { res := BaseResponse{} res.Code = code res.Message = msg r.Ctx.JSON(http.StatusOK, res) }