-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoption.go
90 lines (76 loc) · 2.34 KB
/
option.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
package gohttpclient
import (
"net/http"
"time"
"github.com/cenkalti/backoff/v4"
)
// Option defines the signature of the options configuration family of methods.
type Option func(c *Client)
// WithHTTPClient sets options for a custom http.Client instance.
func WithHTTPClient(client *http.Client) Option {
return func(c *Client) {
c.client = client
}
}
// WithRequestTimeout sets the timeout for the entire request.
func WithRequestTimeout(timeout time.Duration) Option {
return func(c *Client) {
c.requestTimeout = timeout
}
}
// WithMaxBodySize sets the maximum limit on the size of data returned by the server.
func WithMaxBodySize(n uint64) Option {
return func(c *Client) {
c.maxBodySize = n
}
}
// WithShouldRetryFunc sets the function that determines whether a retry is required.
func WithShouldRetryFunc(fn ShouldRetryFunc) Option {
return func(c *Client) {
c.retryOption.ShouldRetryFunc = fn
}
}
// WithMaxRetry sets the maximum number of retries.
// When n=0, it means that no retry operation is performed, instead of retrying until success.
func WithMaxRetry(n uint64) Option {
return func(c *Client) {
c.retryOption.MaxRetry = n
}
}
// WithRetryBackOff sets the retry policy.
// You can choose a constant retry interval, or use an exponential back off algorithm.
func WithRetryBackOff(b backoff.BackOff) Option {
return func(c *Client) {
c.retryOption.RetryBackOff = b
}
}
// WithLoggerOption sets whether to enable the logging function to record the context information of the request.
func WithLoggerOption(option LoggerOption) Option {
return func(c *Client) {
c.loggerOption = option
}
}
// WithRateLimitOption sets the rate-limiting configuration and limits the maximum number of requests per second.
func WithRateLimitOption(option RateLimitOption) Option {
return func(c *Client) {
c.rateLimitOption = option
}
}
// WithHystrixOption sets the configuration of the circuit breaker.
func WithHystrixOption(option HystrixOption) Option {
return func(c *Client) {
c.hystrixOption = option
}
}
// WithTraceOption sets the configuration for distributed call chain tracing.
func WithTraceOption(option TraceOption) Option {
return func(c *Client) {
c.traceOption = option
}
}
// WithCacheOption sets the cache configuration.
func WithCacheOption(option CacheOption) Option {
return func(c *Client) {
c.cacheOption = option
}
}