File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,7 @@ type Client interface {
47
47
}
48
48
49
49
type client struct {
50
- httpClient * http. Client
50
+ httpClient Doer
51
51
endpoint string
52
52
method string
53
53
}
@@ -61,13 +61,20 @@ type client struct {
61
61
//
62
62
// The typical method of adding authentication headers is to wrap the client's
63
63
// Transport to add those headers. See example/caller.go for an example.
64
- func NewClient (endpoint string , httpClient * http. Client ) Client {
65
- if httpClient == nil {
64
+ func NewClient (endpoint string , httpClient Doer ) Client {
65
+ if httpClient == nil || httpClient == ( * http . Client )( nil ) {
66
66
httpClient = http .DefaultClient
67
67
}
68
68
return & client {httpClient , endpoint , http .MethodPost }
69
69
}
70
70
71
+ // Doer encapsulates the methods from *http.Client needed by Client.
72
+ // The methods should have behavior to match that of *http.Client
73
+ // (or mocks for the same).
74
+ type Doer interface {
75
+ Do (* http.Request ) (* http.Response , error )
76
+ }
77
+
71
78
type payload struct {
72
79
Query string `json:"query"`
73
80
Variables interface {} `json:"variables,omitempty"`
You can’t perform that action at this time.
0 commit comments