package response import ( "net/http" "github.com/gin-gonic/gin" "psi/constant" ) type Response struct { Code int `json:"code"` // 状态码 Data interface{} `json:"data"` // 数据 Msg string `json:"msg"` // 消息 } // ExternalAPIResponse 外部接口通用响应结构 type ExternalAPIResponse struct { Code string `json:"code"` // 状态码 Msg string `json:"msg"` // 消息 Data interface{} `json:"data"` // 数据 } func Result(code int, data interface{}, msg string, c *gin.Context) { c.JSON(http.StatusOK, Response{ code, data, msg, }) } func OkWithMessage(message string, c *gin.Context) { Result(constant.SUCCESS, map[string]interface{}{}, message, c) } func OkWithDetailed(data interface{}, message string, c *gin.Context) { Result(constant.SUCCESS, data, message, c) } func FailWithMessage(message string, c *gin.Context) { Result(constant.ERROR, map[string]interface{}{}, message, c) } func FailWithValidateMessage(message string, c *gin.Context) { Result(constant.VALIDATE, map[string]interface{}{}, message, c) } func NoAuth(message string, c *gin.Context) { c.JSON(http.StatusUnauthorized, Response{ constant.OAUTH, nil, message, }) }