Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultRetryConfig = RetryConfig{ MinWait: 1 * time.Second, MaxWait: 30 * time.Second, MaxRetries: 4, CheckRetry: DefaultRetryPolicy, Backoff: DefaultBackoff, }
DefaultRetryConfig is the default config for retrying http requests.
Functions ¶
func DefaultBackoff ¶
DefaultBackoff provides a callback for retryablehttp.Client.Backoff which will perform exponential backoff based on the attempt number and limited by the provided minimum and maximum durations. On 429 responses it will try to parse the Retry-After header use that value as backoff. Will fallback to exponential backoff if the Retry-After header is not present or cannot be parsed.
Types ¶
type HTTPClient ¶
HTTPClient is the interface of an http client that is compatible with *http.Client.
func WithRetries ¶
func WithRetries(httpClient *http.Client, config *RetryConfig) HTTPClient
WithRetries wraps httpClient with backoff-retry logic.
type RetryConfig ¶
type RetryConfig struct { // MinWait is the minimum time to wait before retrying. MinWait time.Duration // MaxWait is the maximum time to wait before retrying. When using // exponential backoff, this is the upper limit for the wait duration. MaxWait time.Duration // MaxRetries is the maximum number of retries to perform until giving up. MaxRetries int // CheckRetry is a function that decides whether a request should be // retried or not. CheckRetry retryablehttp.CheckRetry // Backoff calculates the sleep duration for the next retry. Backoff retryablehttp.Backoff }
RetryConfig configures the backoff-retry behaviour.
Click to show internal directories.
Click to hide internal directories.