-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbasic_def.go
74 lines (63 loc) · 1.56 KB
/
basic_def.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package zerror
type defMapT map[string]*Def
var (
defMap = defMapT{}
)
func init() {
defMap.init()
}
const (
CodeInternal = `zerror:internal`
codeBadRequest = `zerror:bad_request`
codeForbidden = `zerror:forbidden`
codeNofFound = `zerror:not_found`
codeUnauthenticated = `zerror:unauthenticated`
codeAlreadyExists = `zerror:already_exists`
)
var Internal = &Def{
Code: CodeInternal,
Status: StatusInternal,
Msg: `internal error`,
Description: `server internal error`,
}
var BadRequest = &Def{
Code: codeBadRequest,
Status: StatusBadRequest,
Msg: `bad request`,
Description: `bad request`,
}
var Forbidden = &Def{
Code: codeForbidden,
Status: StatusPermissionDenied,
Msg: `forbidden`,
Description: `you are forbidden to access`,
}
var NotFound = &Def{
Code: codeNofFound,
Msg: `not found`,
Status: StatusNotFound,
Description: `resource not found`,
}
var Unauthenticated = &Def{
Code: codeUnauthenticated,
Msg: `unauthenticated`,
Status: StatusUnauthenticated,
Description: `please login`,
}
var AlreadyExists = &Def{
Code: codeAlreadyExists,
Msg: `already exists`,
Status: StatusAlreadyExists,
Description: `already exists`,
}
func (m *defMapT) init() {
inited := defMapT{
CodeInternal: Internal,
codeBadRequest: BadRequest,
codeForbidden: Forbidden,
codeNofFound: NotFound,
codeUnauthenticated: Unauthenticated,
codeAlreadyExists: AlreadyExists,
}
*m = inited
}