-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient_options.go
145 lines (126 loc) · 3.97 KB
/
client_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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package paymail
import (
"time"
"github.com/bitcoin-sv/go-paymail/interfaces"
"github.com/go-resty/resty/v2"
)
// ClientOps allow functional options to be supplied
// that overwrite default go-paymail client options.
type ClientOps func(c *ClientOptions)
// defaultClientOptions will return an ClientOptions struct with the default settings
//
// Useful for starting with the default and then modifying as needed
func defaultClientOptions() (opts *ClientOptions, err error) {
// Set the default options
opts = &ClientOptions{
dnsPort: defaultDNSPort,
dnsTimeout: defaultDNSTimeout,
httpTimeout: defaultHTTPTimeout,
nameServer: defaultNameServer,
nameServerNetwork: defaultNameServerNetwork,
requestTracing: false,
retryCount: defaultRetryCount,
sslDeadline: defaultSSLDeadline,
sslTimeout: defaultSSLTimeout,
userAgent: defaultUserAgent,
network: Network(defaultNetwork),
}
// Load the default BRFC specs
opts.brfcSpecs, err = LoadBRFCs("")
return
}
// WithDNSPort can be supplied with a custom dns port to perform SRV checks on.
// Default is 53.
func WithDNSPort(port string) ClientOps {
return func(c *ClientOptions) {
c.dnsPort = port
}
}
// WithDNSTimeout can be supplied to overwrite the default dns srv check timeout.
// The default is 5 seconds.
func WithDNSTimeout(timeout time.Duration) ClientOps {
return func(c *ClientOptions) {
c.dnsTimeout = timeout
}
}
// WithBRFCSpecs allows custom specs to be supplied to extend or replace the defaults.
func WithBRFCSpecs(specs []*BRFCSpec) ClientOps {
return func(c *ClientOptions) {
c.brfcSpecs = specs
}
}
// WithHTTPTimeout can be supplied to adjust the default http client timeouts.
// The http client is used when querying paymail services for capabilities
// Default timeout is 20 seconds.
func WithHTTPTimeout(timeout time.Duration) ClientOps {
return func(c *ClientOptions) {
c.httpTimeout = timeout
}
}
// WithNameServer can be supplied to overwrite the default name server used to resolve srv requests.
// default is 8.8.8.8.
func WithNameServer(ip string) ClientOps {
return func(c *ClientOptions) {
c.nameServer = ip
}
}
// WithNameServerNetwork can overwrite the default network protocol to use.
// The default is udp.
func WithNameServerNetwork(network string) ClientOps {
return func(c *ClientOptions) {
c.nameServerNetwork = network
}
}
// WithRequestTracing will enable tracing.
// Tracing is disabled by default.
func WithRequestTracing() ClientOps {
return func(c *ClientOptions) {
c.requestTracing = true
}
}
// WithRetryCount will overwrite the default retry count for http requests.
// Default retries is 2.
func WithRetryCount(retries int) ClientOps {
return func(c *ClientOptions) {
c.retryCount = retries
}
}
// WithSSLTimeout will overwrite the default ssl timeout.
// Default timeout is 10 seconds.
func WithSSLTimeout(timeout time.Duration) ClientOps {
return func(c *ClientOptions) {
c.sslTimeout = timeout
}
}
// WithSSLDeadline will overwrite the default ssl deadline.
// Default is 10 seconds.
func WithSSLDeadline(timeout time.Duration) ClientOps {
return func(c *ClientOptions) {
c.sslDeadline = timeout
}
}
// WithUserAgent will overwrite the default useragent.
// Default is go-paymail + version.
func WithUserAgent(userAgent string) ClientOps {
return func(c *ClientOptions) {
c.userAgent = userAgent
}
}
// WithNetwork will set the client's operational network to one provided.
// Default is mainnet.
func WithNetwork(n Network) ClientOps {
return func(c *ClientOptions) {
c.network = n
}
}
// WithCustomResolver will allow you to supply a custom dns resolver,
// useful for testing etc.
func (c *Client) WithCustomResolver(resolver interfaces.DNSResolver) ClientInterface {
c.resolver = resolver
return c
}
// WithCustomHTTPClient will overwrite the default client with a custom client.
func (c *Client) WithCustomHTTPClient(client *resty.Client) ClientInterface {
c.httpClient = client
return c
}