-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.go
More file actions
29 lines (23 loc) · 864 Bytes
/
client.go
File metadata and controls
29 lines (23 loc) · 864 Bytes
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
package cmhttp
import "net/http"
// A Client sends http.Requests and returns http.Responses or errors in case of failure.
// Responses with StatusCode >= 400 are *not* considered a failure.
type Client interface {
Do(*http.Request) (*http.Response, error)
}
// ClientFunc is a function type that implements the Client interface.
type ClientFunc func(*http.Request) (*http.Response, error)
// Do executes this function with the given request as input and returns all results
// without changing them.
func (f ClientFunc) Do(r *http.Request) (*http.Response, error) {
return f(r)
}
// A Decorator wraps a Client with additional behaviour or capabilities.
type Decorator func(Client) Client
// Decorate wraps a Client with all the given Decorators, in order.
func Decorate(c Client, ds ...Decorator) Client {
for _, d := range ds {
c = d(c)
}
return c
}