-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_builder.go
73 lines (60 loc) · 1.57 KB
/
client_builder.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package gohttp
import (
"net/http"
"time"
)
type clientBuilder struct {
headers http.Header
maxIdleConnections int
connectionTimeout time.Duration
requestTimeout time.Duration
disableTimeouts bool
client *http.Client
userAgent string
}
type ClientBuilder interface {
SetHeader(headers http.Header) ClientBuilder
SetConnectionTimeout(timeout time.Duration) ClientBuilder
SetMaxIdleConnections(conn int) ClientBuilder
SetRequestTimeout(timeout time.Duration) ClientBuilder
DisableTimeouts(b bool) ClientBuilder
SetHttpClient(c *http.Client) ClientBuilder
SetUserAgent(userAgent string) ClientBuilder
Build() Client
}
func NewBuilder() ClientBuilder {
return &clientBuilder{}
}
func (c *clientBuilder) Build() Client {
return &httpClient{
builder: c,
}
}
func (c *clientBuilder) SetUserAgent(userAgent string) ClientBuilder {
c.userAgent = userAgent
return c
}
func (c *clientBuilder) SetHttpClient(client *http.Client) ClientBuilder {
c.client = client
return c
}
func (c *clientBuilder) SetHeader(headers http.Header) ClientBuilder {
c.headers = headers
return c
}
func (c *clientBuilder) SetConnectionTimeout(timeout time.Duration) ClientBuilder {
c.connectionTimeout = timeout
return c
}
func (c *clientBuilder) SetMaxIdleConnections(conn int) ClientBuilder {
c.maxIdleConnections = conn
return c
}
func (c *clientBuilder) SetRequestTimeout(timeout time.Duration) ClientBuilder {
c.requestTimeout = timeout
return c
}
func (c *clientBuilder) DisableTimeouts(b bool) ClientBuilder {
c.disableTimeouts = b
return c
}