Documentation ¶
Overview ¶
Package httpretrier allow to retry HTTP requests based on HTTP status code boolean conditions.
Index ¶
Constants ¶
const ( // DefaultAttempts is the default maximum number of retry attempts. DefaultAttempts = 4 // DefaultDelay is the delay to apply after the first failed attempt. DefaultDelay = 1 * time.Second // DefaultDelayFactor is the default multiplication factor to get the successive delay value. DefaultDelayFactor = 2 // DefaultJitter is the maximum random Jitter time between retries. DefaultJitter = 100 * time.Millisecond )
Variables ¶
This section is empty.
Functions ¶
func RetryIfForReadRequests ¶
RetryIfForReadRequests is a retry check function used for read requests (e.g. GET requests that are guaranteed to not modify the remote state).
Types ¶
type HTTPClient ¶
HTTPClient contains the function to perform the actual HTTP request.
type HTTPRetrier ¶
type HTTPRetrier struct {
// contains filtered or unexported fields
}
HTTPRetrier represents an instance of the HTTP retrier.
func New ¶
func New(httpClient HTTPClient, opts ...Option) (*HTTPRetrier, error)
New creates a new instance.
type Option ¶
type Option func(c *HTTPRetrier) error
Option is the interface that allows to set the options.
func WithAttempts ¶
WithAttempts set the maximum number of retries.
func WithDelayFactor ¶
WithDelayFactor set the multiplication factor to get the successive delay value. A delay factor greater than 1 means an exponential delay increase. if the delay factor is 2 and the first delay is 1, then the delays will be: [1, 2, 4, 8, ...].
func WithJitter ¶
WithJitter sets the maximum random Jitter time between retries. This is useful to avoid the Thundering herd problem (https://en.wikipedia.org/wiki/Thundering_herd_problem).
func WithRetryIfFn ¶
WithRetryIfFn set the function used to decide when retry.