-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.go
More file actions
220 lines (193 loc) · 6.66 KB
/
status.go
File metadata and controls
220 lines (193 loc) · 6.66 KB
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
package rsvp
import "net/http"
// Success (2xx)
// StatusCreated sets the response as 201 Created and sets the Location header.
//
// It indicates that a new resource has been successfully created at the given
// location.
func (r Body) StatusCreated(location string) Body {
r.statusCode = http.StatusCreated
r.redirectLocation = location
return r
}
// StatusAccepted sets the response as 202 Accepted.
//
// It indicates that the request has been accepted for processing, but the
// processing has not been completed.
func (r Body) StatusAccepted() Body {
r.statusCode = http.StatusAccepted
return r
}
// StatusNoContent sets the response as 204 No Content.
//
// It indicates that the request was successful but there is no content to
// return. Commonly used for DELETE operations or updates with no response body.
func (r Body) StatusNoContent() Body {
r.statusCode = http.StatusNoContent
return r
}
// Redirection (3xx)
// StatusMovedPermanently sets the response as 301 Moved Permanently and sets
// the Location header.
//
// Moved Permanently is intended for GET requests.
//
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Redirections#permanent_redirections
func (r Body) StatusMovedPermanently(location string) Body {
r.statusCode = http.StatusMovedPermanently
r.redirectLocation = location
return r
}
// StatusFound sets the response as 302 Found and sets the Location header.
//
// It indicates that the requested resource has been temporarily moved to the
// given location.
func (r Body) StatusFound(location string) Body {
r.statusCode = http.StatusFound
r.redirectLocation = location
return r
}
// StatusSeeOther sets the response as 303 See Other and sets the Location
// header.
//
// See Other is used for redirection in response to POST requests.
func (r Body) StatusSeeOther(location string) Body {
r.statusCode = http.StatusSeeOther
r.redirectLocation = location
return r
}
// StatusNotModified sets the response as 304 Not Modified.
//
// It indicates that the resource has not been modified since the version
// specified by the request headers. Used for conditional requests and caching.
func (r Body) StatusNotModified() Body {
r.statusCode = http.StatusNotModified
return r
}
// StatusTemporaryRedirect sets the response as 307 Temporary Redirect and sets
// the Location header.
//
// Temporary Redirect is like 302 Found but guarantees that the HTTP method
// will not be changed when the redirected request is made.
func (r Body) StatusTemporaryRedirect(location string) Body {
r.statusCode = http.StatusTemporaryRedirect
r.redirectLocation = location
return r
}
// StatusPermanentRedirect sets the response as 308 Permanent Redirect and sets
// the Location header.
//
// Permanent Redirect is intended for non-GET requests.
//
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Redirections#permanent_redirections
func (r Body) StatusPermanentRedirect(location string) Body {
r.statusCode = http.StatusPermanentRedirect
r.redirectLocation = location
return r
}
// Client Errors (4xx)
// StatusBadRequest sets the response as 400 Bad Request.
//
// It indicates that the server cannot process the request due to client error,
// such as malformed request syntax or invalid request parameters.
func (r Body) StatusBadRequest() Body {
r.statusCode = http.StatusBadRequest
return r
}
// StatusUnauthorized sets the response as 401 Unauthorized.
//
// It indicates that authentication is required and has failed or has not been
// provided.
func (r Body) StatusUnauthorized() Body {
r.statusCode = http.StatusUnauthorized
return r
}
// StatusForbidden sets the response as 403 Forbidden.
//
// It indicates that the server understood the request but refuses to authorize
// it. Unlike 401, authenticating will make no difference.
func (r Body) StatusForbidden() Body {
r.statusCode = http.StatusForbidden
return r
}
// StatusNotFound sets the response as 404 Not Found.
//
// It indicates that the server cannot find the requested resource.
func (r Body) StatusNotFound() Body {
r.statusCode = http.StatusNotFound
return r
}
// StatusMethodNotAllowed sets the response as 405 Method Not Allowed.
//
// It indicates that the request method is known by the server but is not
// supported by the target resource.
func (r Body) StatusMethodNotAllowed() Body {
r.statusCode = http.StatusMethodNotAllowed
return r
}
// StatusNotAcceptable sets the response as 406 Not Acceptable.
//
// It indicates that the server cannot produce a response matching the list of
// acceptable values defined in the request's proactive content negotiation
// headers.
func (r Body) StatusNotAcceptable() Body {
r.statusCode = http.StatusNotAcceptable
return r
}
// StatusConflict sets the response as 409 Conflict.
//
// It indicates that the request conflicts with the current state of the
// server, such as attempting to create a duplicate resource.
func (r Body) StatusConflict() Body {
r.statusCode = http.StatusConflict
return r
}
// StatusGone sets the response as 410 Gone.
//
// It indicates that the requested resource is no longer available and will not
// be available again. This is a stronger statement than 404 Not Found.
func (r Body) StatusGone() Body {
r.statusCode = http.StatusGone
return r
}
// StatusUnprocessableEntity sets the response as 422 Unprocessable Entity.
//
// It indicates that the request was well-formed but was unable to be followed
// due to semantic errors, such as validation failures.
func (r Body) StatusUnprocessableEntity() Body {
r.statusCode = http.StatusUnprocessableEntity
return r
}
// StatusTooManyRequests sets the response as 429 Too Many Requests.
//
// It indicates that the user has sent too many requests in a given amount of
// time. Used for rate limiting.
func (r Body) StatusTooManyRequests() Body {
r.statusCode = http.StatusTooManyRequests
return r
}
// Server Errors (5xx)
// StatusInternalServerError sets the response as 500 Internal Server Error.
//
// It indicates that the server encountered an unexpected condition that
// prevented it from fulfilling the request.
func (r Body) StatusInternalServerError() Body {
r.statusCode = http.StatusInternalServerError
return r
}
// StatusNotImplemented sets the response as 501 Not Implemented.
//
// It indicates that the server does not support the functionality required to
// fulfill the request.
func (r Body) StatusNotImplemented() Body {
r.statusCode = http.StatusNotImplemented
return r
}
// StatusServiceUnavailable sets the response as 503 Service Unavailable.
//
// It indicates that the server is currently unable to handle the request due
// to temporary overload or scheduled maintenance.
func (r Body) StatusServiceUnavailable() Body {
r.statusCode = http.StatusServiceUnavailable
return r
}