1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- package response
- import (
- "net/http"
- "github.com/gin-gonic/gin"
- )
- const (
- ERROR int = -1
- SUCCESS int = 0
- //服务级错误码
- EmptyResult int = 201 //查询无结果
- ParamError int = 202 //参数错误
- ParamEmpty = 203 //参数为空
- ParamLenInValid int = 204 //参数长度小于4
- Waiting int = 205 //等待处理中
- MoreThanQueryDataNumberLimit int = 206 //请求数据的条数超过上限
- LeftNumEmpty = 207 //余额不足
- QueryError int = 299 //系统查询异常,请联系客服
- //系统级错误码
- InValidKey = 101 //当前KEY无效
- RemainingLack = 102 //当前KEY余额|余量不足
- DeleteKey = 103 //当前Key被暂停使用,请联系管理员
- TokenInvalid = 104 //身份验证错误
- TokenExpired = 107 //身份验证已过期
- //105非法请求过多,请联系管理员
- IpInvalid = 108 //被禁止的IP
- MoreThanEveryDayQueryTimesLimit = 109 //请求超过每日系统限制
- //108当前相同查询连续出错,请等2小时后重试
- InterfaceRightInvalid = 110 //接口权限未开通
- InterfaceExpired = 111 //您的账号剩余使用量已过期
- InterfaceDeleted = 112 //接口已停用,请联系管理员
- MoreThanEveryDayDataNumberLimit = 113 //请求超过每日调用总量限制
- OtherError = 199 //系统未知错误,请联系技术客服
- )
- type Response struct {
- Code int `json:"code"`
- Data interface{} `json:"data"`
- Msg string `json:"msg"`
- }
- type ResponseArr struct {
- Code int `json:"code"`
- Data []map[string]interface{} `json:"data"`
- Msg string `json:"msg"`
- }
- func Result(code int, data interface{}, msg string, c *gin.Context) {
- c.JSON(http.StatusOK, Response{
- code,
- data,
- msg,
- })
- }
- func ResultArr(code int, data []map[string]interface{}, msg string, c *gin.Context) {
- c.JSON(http.StatusOK, ResponseArr{
- 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 OkWithDatas(data []map[string]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(code int, data interface{}, message string, c *gin.Context) {
- Result(code, data, message, c)
- }
|