package bean import ( "github.com/gin-gonic/gin" "net/http" ) var Response = &response{} type response struct { Code int `json:"code"` Msg string `json:"msg"` Data interface{} `json:"data"` } // @Title 返回成功 func (r *response) ResultSuc(c *gin.Context, msg string, data interface{}) { c.JSON(http.StatusOK, response{ Code: 0, Msg: msg, Data: data, }) } // @Title 返回失败 func (r *response) ResultFail(c *gin.Context, code int, msg string, data ...interface{}) { if len(data) > 0 { c.JSON(http.StatusOK, response{ Code: code, Msg: msg, Data: data[0], }) } else { c.JSON(http.StatusOK, response{ Code: code, Msg: msg, Data: nil, }) } }