render.go
1.48 KB
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
57
58
59
package render
import (
"errors"
"net/http"
"github.com/meiqia/chi/render"
"client/gift/common"
)
func JSON(w http.ResponseWriter, r *http.Request, statusCode int, resp interface{}) {
render.Status(r, statusCode)
render.JSON(w, r, resp)
}
func BindError(w http.ResponseWriter, r *http.Request, err error) {
JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.BugInfoBindFailed,
"msg": common.Errors[common.BugInfoBindFailed] + err.Error(),
})
}
func InternalError(w http.ResponseWriter, r *http.Request, err error) {
if err == nil {
err = errors.New("未知错误")
}
JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.BugInfoInternalError,
"msg": common.Errors[common.BugInfoInternalError] + err.Error(),
})
}
func InternalNullError(w http.ResponseWriter, r *http.Request, err error) {
if err == nil {
err = errors.New("未知错误")
}
JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.BugInfoClientNull,
"msg": common.Errors[common.BugInfoClientNull] + err.Error(),
})
}
func TaskRepeatError(w http.ResponseWriter, r *http.Request, err error) {
if err == nil {
err = errors.New(" taskId 重复 ")
}
JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.BugInfoTaskRepeat,
"msg": common.Errors[common.BugInfoTaskRepeat] + err.Error(),
})
}
func Success(w http.ResponseWriter, r *http.Request) {
JSON(w, r, http.StatusOK, map[string]interface{}{
"code": common.OK,
"msg": common.Errors[common.OK],
})
}