-
Notifications
You must be signed in to change notification settings - Fork 1
/
interfaces.go
45 lines (40 loc) · 1.48 KB
/
interfaces.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
package requestclient
import (
"net"
"net/http"
)
// DialDialer - is an interface for connecting to an address.
type DialDialer interface {
Dial(network, address string) (net.Conn, error)
}
// RoundTripper is an interface representing the ability to execute a
// single HTTP transaction, obtaining the Response for a given Request.
//
// A RoundTripper must be safe for concurrent use by multiple
// goroutines.
type RoundTripper interface {
// RoundTrip executes a single HTTP transaction, returning
// the Response for the request req. RoundTrip should not
// attempt to interpret the response. In particular,
// RoundTrip must return err == nil if it obtained a response,
// regardless of the response's HTTP status code. A non-nil
// err should be reserved for failure to obtain a response.
// Similarly, RoundTrip should not attempt to handle
// higher-level protocol details such as redirects,
// authentication, or cookies.
//
// RoundTrip should not modify the request, except for
// consuming and closing the Body, including on errors. The
// request's URL and Header fields are guaranteed to be
// initialized.
RoundTrip(*http.Request) (*http.Response, error)
}
// ClientRequester - higher level API that implements http.Client
type ClientRequester interface {
Do(req *http.Request) (*http.Response, error)
}
// Requester - wraps RoundTripper & ClientRequester
type Requester interface {
Do(*http.Request) (*http.Response, error)
RoundTrip(*http.Request) (*http.Response, error)
}