-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathresponse_fluent_status.go
66 lines (51 loc) · 1.5 KB
/
response_fluent_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
package fastshot
import (
"fmt"
"net/http"
)
type ResponseFluentStatus struct {
response *http.Response
}
func (r *Response) Status() *ResponseFluentStatus {
return r.status
}
func (r *ResponseFluentStatus) Code() int {
return r.response.StatusCode
}
func (r *ResponseFluentStatus) Text() string {
return fmt.Sprintf(
"[%d] %s",
r.response.StatusCode,
http.StatusText(r.response.StatusCode),
)
}
func (r *ResponseFluentStatus) Is1xxInformational() bool {
return r.response.StatusCode >= 100 && r.response.StatusCode < 200
}
func (r *ResponseFluentStatus) Is2xxSuccessful() bool {
return r.response.StatusCode >= 200 && r.response.StatusCode < 300
}
func (r *ResponseFluentStatus) Is3xxRedirection() bool {
return r.response.StatusCode >= 300 && r.response.StatusCode < 400
}
func (r *ResponseFluentStatus) Is4xxClientError() bool {
return r.response.StatusCode >= 400 && r.response.StatusCode < 500
}
func (r *ResponseFluentStatus) Is5xxServerError() bool {
return r.response.StatusCode >= 500 && r.response.StatusCode < 600
}
func (r *ResponseFluentStatus) IsOK() bool {
return r.Code() == http.StatusOK
}
func (r *ResponseFluentStatus) IsNotFound() bool {
return r.Code() == http.StatusNotFound
}
func (r *ResponseFluentStatus) IsUnauthorized() bool {
return r.Code() == http.StatusUnauthorized
}
func (r *ResponseFluentStatus) IsForbidden() bool {
return r.Code() == http.StatusForbidden
}
func (r *ResponseFluentStatus) IsError() bool {
return r.Is4xxClientError() || r.Is5xxServerError()
}