-
Notifications
You must be signed in to change notification settings - Fork 0
/
return.go
56 lines (51 loc) · 1.33 KB
/
return.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package antd
import (
"github.com/gin-gonic/gin"
"github.com/lvyasen/go-admin-core/sdk/pkg"
"net/http"
)
// Error 失败数据处理
func Error(c *gin.Context, errCode string, errMsg string, showType string) {
var res response
res.Success = false
if errMsg != "" {
res.ErrorMessage = errMsg
}
if showType != "" {
res.ShowType = showType
}
res.TraceId = pkg.GenerateMsgIDFromContext(c)
res.ErrorCode = errCode
c.Set("result", res)
c.Set("status", errCode)
c.AbortWithStatusJSON(http.StatusOK, res)
}
// OK 通常成功数据处理
func OK(c *gin.Context, data interface{}) {
var res response
res.Data = data
res.Success = true
res.TraceId = pkg.GenerateMsgIDFromContext(c)
c.Set("result", res)
c.Set("status", http.StatusOK)
c.AbortWithStatusJSON(http.StatusOK, res)
}
// PageOK 分页数据处理
func PageOK(c *gin.Context, result interface{}, total int, current int, pageSize int) {
var res pages
res.Data = result
res.Total = total
res.Current = current
res.PageSize = pageSize
res.Success = true
res.TraceId = pkg.GenerateMsgIDFromContext(c)
c.Set("result", res)
c.Set("status", http.StatusOK)
c.AbortWithStatusJSON(http.StatusOK, res)
}
// Custum 兼容函数
func Custum(c *gin.Context, data gin.H) {
data["traceId"] = pkg.GenerateMsgIDFromContext(c)
c.Set("result", data)
c.AbortWithStatusJSON(http.StatusOK, data)
}