-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.go
55 lines (49 loc) · 1.44 KB
/
common.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
package td
import "math"
const (
// 公用错误码
CodeUnknownError = -1
CodeWriteFailed = 104
CodeInvalidParameter = 299
CodeBadPacket = 400
CodeUnauthorized = 401
CodeNotFound = 404
CodeInternalServerError = 500
CodeBadGateway = 502
)
// CodeMessage
func CodeMessage(rerrCode int) string {
switch rerrCode {
case CodeBadPacket:
return "Bad Packet"
case CodeUnauthorized:
return "Unauthorized"
case CodeWriteFailed:
return "Write Failed"
case CodeNotFound:
return "Not Found"
case CodeInternalServerError:
return "Internal Server Error"
case CodeBadGateway:
return "Bad Gateway"
case CodeUnknownError:
fallthrough
case CodeInvalidParameter:
return "Invalid Parameter"
default:
return "Unknown Error"
}
}
var (
// 公用错误
RerrUnknown = NewRerror(CodeUnknownError, CodeMessage(CodeUnknownError), "")
RerrWriteFailed = NewRerror(CodeWriteFailed, CodeMessage(CodeWriteFailed), "")
RerrInvalidParameter = NewRerror(CodeInvalidParameter, CodeMessage(CodeInvalidParameter), "")
RerrBadPacket = NewRerror(CodeBadPacket, CodeMessage(CodeBadPacket), "")
RerrNotFound = NewRerror(CodeNotFound, CodeMessage(CodeNotFound), "")
RerrInternalServer = NewRerror(CodeInternalServerError, CodeMessage(CodeInternalServerError), "")
RerrBadGateway = NewRerror(CodeBadGateway, CodeMessage(CodeBadGateway), "")
)
const (
abortIndex int = math.MaxInt8 / 2
)