forked from s32x/httpclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
46 lines (39 loc) · 892 Bytes
/
client.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
46
package httpclient
import (
"net/http"
"sync"
"time"
)
// Client is an http.Client wrapper
type Client struct {
client *http.Client
baseURL string
header sync.Map
}
// New creates a new Client reference given a client timeout
func New() *Client {
return &Client{
client: &http.Client{},
header: sync.Map{},
}
}
// WithClient sets the http client on the Client
func (c *Client) WithClient(client *http.Client) *Client {
c.client = client
return c
}
// WithTimeout sets the timeout on the http client
func (c *Client) WithTimeout(timeout time.Duration) *Client {
c.client.Timeout = timeout
return c
}
// WithBaseURL sets the baseURL on the Client
func (c *Client) WithBaseURL(url string) *Client {
c.baseURL = url
return c
}
// WithHeader sets the headers on the Client
func (c *Client) WithHeader(key, value string) *Client {
c.header.Store(key, value)
return c
}