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