mirror of
https://github.com/d0zingcat/gocryptotrader.git
synced 2026-05-14 23:16:49 +00:00
Refactoring the timeout retries into a more general 'retry policy' with support for retrying on HTTP 429 (Too Many Requests) and other responses with a `Retry-After` header The delay between requests is controlled by a combination of a 'backoff' (currently only a simple linear backoff), and honouring the `Retry-After` value (longest delay wins) This makes the 'rate limiter' an optional argument as well, removing the use of `nil` when one isn't supplied Signed-off-by: David Ackroyd <daveo.ackroyd@gmail.com>
23 lines
507 B
Go
23 lines
507 B
Go
package request
|
|
|
|
// WithBackoff configures the backoff strategy for a Requester.
|
|
func WithBackoff(b Backoff) RequesterOption {
|
|
return func(r *Requester) {
|
|
r.backoff = b
|
|
}
|
|
}
|
|
|
|
// WithLimiter configures the rate limiter for a Requester.
|
|
func WithLimiter(l Limiter) RequesterOption {
|
|
return func(r *Requester) {
|
|
r.limiter = l
|
|
}
|
|
}
|
|
|
|
// WithRetryPolicy configures the retry policy for a Requester.
|
|
func WithRetryPolicy(p RetryPolicy) RequesterOption {
|
|
return func(r *Requester) {
|
|
r.retryPolicy = p
|
|
}
|
|
}
|