-
Notifications
You must be signed in to change notification settings - Fork 4
/
status.go
75 lines (66 loc) · 2.8 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
package requests
import "fmt"
const (
INFO_CONTINUE = 100
INFO_SWITCHING_PROTOCOL = 101
INFO_PROCESSING = 102
SUCCESS_OK = 200
SUCCESS_CREATED = 201
SUCCESS_ACCEPTED = 202
SUCCESS_NON_AUTHORITATIVE = 203
SUCCESS_NO_CONTENT = 204
SUCCESS_RESET_CONTENT = 205
SUCCESS_PARTIAL_CONTENT = 206
SUCCESS_MULTI_STATUS = 207
REDIRECTION_MULTIPLE_CHOICES = 300
REDIRECTION_MOVED_PERMANENTLY = 301
REDIRECTION_MOVED_TEMPORARILY = 302
REDIRECTION_SEE_OTHER = 303
REDIRECTION_NOT_MODIFIED = 304
REDIRECTION_USE_PROXY = 305
REDIRECTION_TEMPORARY_REDIRECT = 307
CLIENT_ERROR_BAD_REQUEST = 400
CLIENT_ERROR_UNAUTHORIZED = 401
CLIENT_ERROR_PAYMENT_REQUIRED = 402
CLIENT_ERROR_FORBIDDEN = 403
CLIENT_ERROR_NOT_FOUND = 404
CLIENT_ERROR_METHOD_NOT_ALLOWED = 405
CLIENT_ERROR_NOT_ACCEPTABLE = 406
CLIENT_ERROR_PROXY_AUTHENTIFICATION_REQUIRED = 407
CLIENT_ERROR_REQUEST_TIMEOUT = 408
CLIENT_ERROR_CONFLICT = 409
CLIENT_ERROR_GONE = 410
CLIENT_ERROR_LENGTH_REQUIRED = 411
CLIENT_ERROR_PRECONDITION_FAILED = 412
CLIENT_ERROR_REQUEST_ENTITY_TOO_LARGE = 413
CLIENT_ERROR_REQUEST_URI_TOO_LONG = 414
CLIENT_ERROR_UNSUPPORTED_MEDIA_TYPE = 415
CLIENT_ERROR_REQUESTED_RANGE_NOT_SATISFIABLE = 416
CLIENT_ERROR_EXPECTATION_FAILED = 417
CLIENT_ERROR_UNPROCESSABLE_ENTITY = 422
CLIENT_ERROR_LOCKED = 423
CLIENT_ERROR_FAILED_DEPENDENCY = 424
SERVER_ERROR_INTERNAL = 500
SERVER_ERROR_NOT_IMPLEMENTED = 501
SERVER_ERROR_BAD_GATEWAY = 502
SERVER_ERROR_SERVICE_UNAVAILABLE = 503
SERVER_ERROR_GATEWAY_TIMEOUT = 504
SERVER_ERROR_HTTP_VERSION_NOT_SUPPORTED = 505
SERVER_ERROR_INSUFFICIENT_STORAGE = 507
)
// Status is a HTTP reponse status.
type Status struct {
Code int
Reason string
}
func (s *Status) String() string { return fmt.Sprintf("%d %s", s.Code, s.Reason) }
func (s Status) IsInformational() bool { return s.Code >= INFO_CONTINUE && s.Code < SUCCESS_OK }
func (s Status) IsSuccess() bool { return s.Code >= SUCCESS_OK && s.Code < REDIRECTION_MULTIPLE_CHOICES }
func (s Status) IsRedirect() bool {
return s.Code >= REDIRECTION_MULTIPLE_CHOICES && s.Code < CLIENT_ERROR_BAD_REQUEST
}
func (s Status) IsError() bool { return s.Code >= CLIENT_ERROR_BAD_REQUEST }
func (s Status) IsClientError() bool {
return s.Code >= CLIENT_ERROR_BAD_REQUEST && s.Code < SERVER_ERROR_INTERNAL
}
func (s Status) IsServerError() bool { return s.Code >= SERVER_ERROR_INTERNAL }