package response import ( "github.com/gin-gonic/gin" "net/http" ) type Response struct { Code int `json:"code"` Data interface{} `json:"data"` Msg string `json:"msg"` } const ( ERROR = 7 SUCCESS = 0 ) func result(code int, data interface{}, msg string, c *gin.Context) { // 开始时间 c.JSON(http.StatusOK, Response{ code, data, msg, }) } func Ok(c *gin.Context) { result(SUCCESS, map[string]interface{}{}, "操作成功", c) } func OkWithMessage(message string, c *gin.Context) { result(SUCCESS, map[string]interface{}{}, message, c) } func OkWithData(data interface{}, c *gin.Context) { result(SUCCESS, data, "查询成功", c) } func OkWithDetailed(data interface{}, message string, c *gin.Context) { result(SUCCESS, data, message, c) } func Fail(c *gin.Context) { result(ERROR, map[string]interface{}{}, "操作失败", c) } func FailWithMessage(message string, c *gin.Context) { result(ERROR, map[string]interface{}{}, message, c) } func FailWithDetailed(data interface{}, message string, c *gin.Context) { result(ERROR, data, message, c) }