-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
85 lines (75 loc) · 2.01 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package circlesdk
import (
"errors"
"os"
)
// Option settings allow you to customize the behavior of a client
// instance.
type Option func(*Client) error
// WithUserAgent adjust the network agent value reported to the service.
func WithUserAgent(agent string) Option {
return func(c *Client) error {
c.UserAgent = agent
return nil
}
}
// WithKeepAlive adjust the time to maintain open the connection with the
// service, in seconds.
func WithKeepAlive(val uint) Option {
return func(c *Client) error {
c.KeepAlive = val
return nil
}
}
// WithMaxConnections adjusts the maximum number of network connections to
// keep open with the service.
func WithMaxConnections(val uint) Option {
return func(c *Client) error {
c.MaxConnections = val
return nil
}
}
// WithTimeout specifies a time limit for requests made by this client. The
// timeout includes connection time, any redirects, and reading the response
// body. A timeout of zero means no timeout.
func WithTimeout(val uint) Option {
return func(c *Client) error {
c.Timeout = val
return nil
}
}
// WithAPIKey specifies the Circle API key used to access the service.
func WithAPIKey(key string) Option {
return func(c *Client) error {
c.Key = key
return nil
}
}
// WithAPIKeyFromEnv loads the Circle API key from the ENV variable specified
// in 'name'.
func WithAPIKeyFromEnv(name string) Option {
return func(c *Client) error {
c.Key = os.Getenv(name)
if c.Key == "" {
return errors.New("env variable not available")
}
return nil
}
}
// WithDebug makes the client produce trace output of requests and responses.
// Recommended only for testing and development.
func WithDebug() Option {
return func(c *Client) error {
c.Debug = true
return nil
}
}
// WithProductionBackend adjust the client to consume the production API.
// If not specified, the client will submit requests to the sandbox environment
// by default.
func WithProductionBackend() Option {
return func(c *Client) error {
c.Backend = endpointProduction
return nil
}
}