-
Notifications
You must be signed in to change notification settings - Fork 1
/
codes.go
124 lines (112 loc) · 2.29 KB
/
codes.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package http
// StatusCode is an alias for int using as a http status code
type StatusCode int
// IsInformational check if status code is informational
func (s StatusCode) IsInformational() bool {
return s >= 100 && s < 200
}
// IsSuccess check if status code is success
func (s StatusCode) IsSuccess() bool {
return s >= 200 && s < 300
}
// IsRedirection check if status code is redirection
func (s StatusCode) IsRedirection() bool {
return s >= 300 && s < 400
}
// IsClientError check if status code is client error
func (s StatusCode) IsClientError() bool {
return s >= 400 && s < 500
}
// IsInternalError check if status code is internal error
func (s StatusCode) IsInternalError() bool {
return s > 500
}
// Int cast the status code to int value
func (s StatusCode) Int() int {
return int(s)
}
// Informational HTTP Status Codes
const (
Continue StatusCode = iota + 100
SwitchingProtocols
Processing
)
// Success HTTP Status Codes
const (
OK StatusCode = iota + 200
Created
Accepted
NonAuthoritativeInformation
NoContent
ResetContent
PartialContent
MultiStatus
AlreadyReported
IMUsed StatusCode = 226
)
// Redirection HTTP Status Code
const (
MultipleChoices StatusCode = iota + 300
MovedPermanently
Found
SeeOther
NotModified
UseProxy
_
TemporaryRedirect
PermanentRedirect
)
// Client Error HTTP Status Code
const (
BadRequest StatusCode = iota + 400
Unauthorized
PaymentRequired
Forbidden
NotFound
MethodNotAllowed
NotAcceptable
ProxyAuthenticationRequired
RequestTimeout
Conflict
Gone
LengthRequired
PreconditionFailed
PayloadTooLarge
RequestURITooLong
UnsupportedMediaType
RequestedRangeNotSatisfiable
ExpectationFailed
ImATeapot
_
_
MisdirectedRequest
UnprocessableEntity
Locked
FailedDependency
_
UpgradeRequired
_
PreconditionRequired
TooManyRequests
_
RequestHeaderFieldsTooLarge
ConnectionClosedWithoutResponse StatusCode = 444
UnavailableForLegalReasons StatusCode = 451
ClientClosedRequest StatusCode = 499
)
// Server Error HTTP Status Code
const (
InternalServerError StatusCode = iota + 500
NotImplemented
BadGateway
ServiceUnavailable
GatewayTimeout
VersionNotSupported
VariantAlsoNegotiates
InsufficientStorage
LoopDetected
_
NotExtended
NetworkAuthenticationRequired
NetworkConnectTimeoutError StatusCode = 599
)