forked from dreamans/syncd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrender.go
51 lines (42 loc) · 1.13 KB
/
render.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
// Copyright 2018 syncd Author. All Rights Reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package syncd
import (
"net/http"
"errors"
"fmt"
"github.com/tinystack/goweb"
)
const (
CODE_OK = 0
CODE_ERR_SYSTEM = 1000
CODE_ERR_APP = 1001
CODE_ERR_PARAM = 1002
CODE_ERR_DATA_REPEAT = 1003
CODE_ERR_LOGIN_FAILED = 1004
CODE_ERR_NO_LOGIN = 1005
CODE_ERR_NO_PRIV = 1006
CODE_ERR_TASK_ERROR = 1007
CODE_ERR_USER_OR_PASS_WRONG = 1008
)
func RenderParamError(msg string) error {
return RenderCustomerError(CODE_ERR_PARAM, msg)
}
func RenderAppError(msg string) error {
return RenderCustomerError(CODE_ERR_APP, msg)
}
func RenderTaskError(msg string) error {
return RenderCustomerError(CODE_ERR_TASK_ERROR, msg)
}
func RenderCustomerError(code int, msg string) error {
return errors.New(fmt.Sprintf("%d=>%s", code, msg))
}
func RenderJson(c *goweb.Context, data interface{}) error {
c.Json(http.StatusOK, goweb.JSON{
"code": CODE_OK,
"message": "success",
"data": data,
})
return nil
}