Add option for client with custom http client (#159)
This commit is contained in:
parent
a669487e86
commit
ac8746b2cf
1 changed files with 9 additions and 1 deletions
|
@ -36,6 +36,12 @@ func NewClient(url, token string) *Client {
|
|||
}
|
||||
}
|
||||
|
||||
// NewClientWithHTTP creates an API client with a custom http client
|
||||
func NewClientWithHTTP(url string, httpClient *http.Client) {
|
||||
client := NewClient(url, "")
|
||||
client.client = httpClient
|
||||
}
|
||||
|
||||
// SetHTTPClient replaces default http.Client with user given one.
|
||||
func (c *Client) SetHTTPClient(client *http.Client) {
|
||||
c.client = client
|
||||
|
@ -51,7 +57,9 @@ func (c *Client) doRequest(method, path string, header http.Header, body io.Read
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(c.accessToken) != 0 {
|
||||
req.Header.Set("Authorization", "token "+c.accessToken)
|
||||
}
|
||||
if c.sudo != "" {
|
||||
req.Header.Set("Sudo", c.sudo)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue