-
Notifications
You must be signed in to change notification settings - Fork 3
/
status.go
231 lines (186 loc) · 6 KB
/
status.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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
package response
import "net/http"
import "fmt"
// respond with the given message.
func text(w http.ResponseWriter, code int, msg string) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.WriteHeader(code)
fmt.Fprintln(w, msg)
}
// write `msg` to the response writer, currently only a single argument is supported.
func write(w http.ResponseWriter, code int, msg []interface{}) {
if len(msg) == 0 {
text(w, code, http.StatusText(code))
return
}
switch msg[0].(type) {
case string:
text(w, code, msg[0].(string))
default:
JSON(w, msg[0], code)
}
}
// Continue response.
func Continue(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusContinue, msg)
}
// SwitchingProtocols response.
func SwitchingProtocols(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusSwitchingProtocols, msg)
}
// OK response.
func OK(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusOK, msg)
}
// Created response.
func Created(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusCreated, msg)
}
// Accepted response.
func Accepted(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusAccepted, msg)
}
// NonAuthoritativeInfo response.
func NonAuthoritativeInfo(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNonAuthoritativeInfo, msg)
}
// NoContent response.
func NoContent(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNoContent, msg)
}
// ResetContent response.
func ResetContent(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusResetContent, msg)
}
// PartialContent response.
func PartialContent(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusPartialContent, msg)
}
// MultipleChoices response.
func MultipleChoices(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusMultipleChoices, msg)
}
// MovedPermanently response.
func MovedPermanently(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusMovedPermanently, msg)
}
// Found response.
func Found(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusFound, msg)
}
// SeeOther response.
func SeeOther(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusSeeOther, msg)
}
// NotModified response.
func NotModified(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNotModified, msg)
}
// UseProxy response.
func UseProxy(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusUseProxy, msg)
}
// TemporaryRedirect response.
func TemporaryRedirect(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusTemporaryRedirect, msg)
}
// BadRequest response.
func BadRequest(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusBadRequest, msg)
}
// Unauthorized response.
func Unauthorized(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusUnauthorized, msg)
}
// PaymentRequired response.
func PaymentRequired(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusPaymentRequired, msg)
}
// Forbidden response.
func Forbidden(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusForbidden, msg)
}
// NotFound response.
func NotFound(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNotFound, msg)
}
// MethodNotAllowed response.
func MethodNotAllowed(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusMethodNotAllowed, msg)
}
// NotAcceptable response.
func NotAcceptable(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNotAcceptable, msg)
}
// ProxyAuthRequired response.
func ProxyAuthRequired(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusProxyAuthRequired, msg)
}
// RequestTimeout response.
func RequestTimeout(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusRequestTimeout, msg)
}
// Conflict response.
func Conflict(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusConflict, msg)
}
// Gone response.
func Gone(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusGone, msg)
}
// LengthRequired response.
func LengthRequired(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusLengthRequired, msg)
}
// PreconditionFailed response.
func PreconditionFailed(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusPreconditionFailed, msg)
}
// RequestEntityTooLarge response.
func RequestEntityTooLarge(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusRequestEntityTooLarge, msg)
}
// RequestURITooLong response.
func RequestURITooLong(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusRequestURITooLong, msg)
}
// UnsupportedMediaType response.
func UnsupportedMediaType(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusUnsupportedMediaType, msg)
}
// RequestedRangeNotSatisfiable response.
func RequestedRangeNotSatisfiable(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusRequestedRangeNotSatisfiable, msg)
}
// ExpectationFailed response.
func ExpectationFailed(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusExpectationFailed, msg)
}
// Teapot response.
func Teapot(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusTeapot, msg)
}
// InternalServerError response.
func InternalServerError(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusInternalServerError, msg)
}
// NotImplemented response.
func NotImplemented(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusNotImplemented, msg)
}
// BadGateway response.
func BadGateway(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusBadGateway, msg)
}
// ServiceUnavailable response.
func ServiceUnavailable(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusServiceUnavailable, msg)
}
// GatewayTimeout response.
func GatewayTimeout(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusGatewayTimeout, msg)
}
// HTTPVersionNotSupported response.
func HTTPVersionNotSupported(w http.ResponseWriter, msg ...interface{}) {
write(w, http.StatusHTTPVersionNotSupported, msg)
}