-
-
Notifications
You must be signed in to change notification settings - Fork 113
/
code_string.go
58 lines (54 loc) · 1.6 KB
/
code_string.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
package codes
import (
"errors"
"strconv"
)
var codeToString = map[Code]string{
Empty: "Empty",
GET: "GET",
POST: "POST",
PUT: "PUT",
DELETE: "DELETE",
Created: "Created",
Deleted: "Deleted",
Valid: "Valid",
Changed: "Changed",
Content: "Content",
BadRequest: "BadRequest",
Unauthorized: "Unauthorized",
BadOption: "BadOption",
Forbidden: "Forbidden",
NotFound: "NotFound",
MethodNotAllowed: "MethodNotAllowed",
NotAcceptable: "NotAcceptable",
PreconditionFailed: "PreconditionFailed",
RequestEntityTooLarge: "RequestEntityTooLarge",
UnsupportedMediaType: "UnsupportedMediaType",
TooManyRequests: "TooManyRequests",
InternalServerError: "InternalServerError",
NotImplemented: "NotImplemented",
BadGateway: "BadGateway",
ServiceUnavailable: "ServiceUnavailable",
GatewayTimeout: "GatewayTimeout",
ProxyingNotSupported: "ProxyingNotSupported",
CSM: "Capabilities and Settings Messages",
Ping: "Ping",
Pong: "Pong",
Release: "Release",
Abort: "Abort",
}
func (c Code) String() string {
val, ok := codeToString[c]
if ok {
return val
}
return "Code(" + strconv.FormatInt(int64(c), 10) + ")"
}
func ToCode(v string) (Code, error) {
for key, val := range codeToString {
if v == val {
return key, nil
}
}
return 0, errors.New("not found")
}