-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
71 lines (61 loc) · 1.43 KB
/
options.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
package goclient
import (
"fmt"
"net/http"
"time"
"github.com/afex/hystrix-go/hystrix"
)
// OptFunc is a functor which receives a Client instance and override
// its members
type OptFunc func(client *Client) error
func WithHTTPClient(httpClient *http.Client) OptFunc {
return func(client *Client) error {
client.httpClient = httpClient
return nil
}
}
func WithTLSConfig(tlsOpts *TLSOptions) OptFunc {
return func(client *Client) error {
tlsConfig, err := NewTLSConfig(tlsOpts)
if err != nil {
return err
}
transport, ok := client.httpClient.Transport.(*http.Transport)
if ok {
transport.TLSClientConfig = tlsConfig
return nil
}
return fmt.Errorf("failed to apply tls config on %T", client.httpClient.Transport)
}
}
func WithHTTPTimeout(timeout time.Duration) OptFunc {
return func(client *Client) error {
client.httpClient.Timeout = timeout
return nil
}
}
func WithCustomHeaders(headers http.Header) OptFunc {
return func(client *Client) error {
client.headers = headers
return nil
}
}
func WithHystrix(conf *HystrixConfig) OptFunc {
return func(client *Client) error {
hystrix.ConfigureCommand(conf.Name, conf.CommandConfig)
client.hystrixConfig = conf
return nil
}
}
func WithDebug() OptFunc {
return func(client *Client) error {
client.debug = true
return nil
}
}
func WithNewRelicEnable() OptFunc {
return func(client *Client) error {
client.enableNewRelic = true
return nil
}
}