-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathstatus.go
More file actions
46 lines (36 loc) · 1.32 KB
/
status.go
File metadata and controls
46 lines (36 loc) · 1.32 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
package httpx
import "net/http"
// ResponseIsSuccessful returns whether the response is successful
func ResponseIsSuccessful(resp *http.Response) bool {
return IsSuccessful(resp.StatusCode)
}
// ResponseIsRedirection returns whether the response is a redirect
func ResponseIsRedirection(resp *http.Response) bool {
return IsRedirection(resp.StatusCode)
}
// ResponseIsClientError returns whether the response is a client error
func ResponseIsClientError(resp *http.Response) bool {
return IsClientError(resp.StatusCode)
}
// ResponseIsServerError returns whether the response is a server error
func ResponseIsServerError(resp *http.Response) bool {
return IsServerError(resp.StatusCode)
}
// StatusFunc is a function that recives a status code and returns a boolean.
type StatusFunc func(code int) bool
// IsSuccessful returns whether the response is successful
func IsSuccessful(code int) bool {
return code >= 200 && code < 300
}
// IsRedirection returns whether the codeonse is a redirect
func IsRedirection(code int) bool {
return code >= 300 && code < 400
}
// IsClientError returns whether the codeonse is a client error
func IsClientError(code int) bool {
return code >= 400 && code < 500
}
// IsServerError returns whether the codeonse is a server error
func IsServerError(code int) bool {
return code >= 500 && code < 600
}