Documentation
¶
Index ¶
Constants ¶
const ( DefaultMaxRetries = 5 DefaultInitialDuration = 2 * time.Minute )
Variables ¶
var ErrorNoMoreAttempts = errors.New("request cannot by retried")
Functions ¶
func DefaultBackoff ¶
DefaultBackoff will double the duration d if it is greater than zero, otherwise it returns 1 minute.
func NewRoundTripper ¶
func NewRoundTripper(inner http.RoundTripper, o ...Option) http.RoundTripper
Types ¶
type BackoffFn ¶
A BackoffFn takes the previous delay and calculates a new, longer delay.
This is used to extend the time between retries.
type Option ¶
type Option interface {
Apply(*Options)
}
func InitialDelay ¶
func MaxRetries ¶
func RetryAfter ¶
func RetryAfter(ra RetryAfterFn) Option
func Strategy ¶
func Strategy(rs RetryStrategyFn) Option
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func (*Request) Done ¶
Done indicates whether or not the request can be attempted any more times.
Initially Done will be false. It will move to true when the following occurs:
- Do returns a 2xx or 3xx response
- Do returns an error
- The number of attempts exceeds MaxRetries
- No RetryStrategy was returned or only NoRetry, and RetryAfter() had no delay.
If Done returns true, Do must never be called again, otherwise Do will return ErrorNoMoreAttempts.
If Done returns false, Do needs to be called.
If Do has never been called, this method will always return false.
type RetryAfterFn ¶
A RetryAfterFn is used to parse the delay from the Retry-After header.
The returned time.Duration will be used as the delay.
If the header is not set, or the value cannot be parsed, a Duration of 0 must be returned.
type RetryStrategy ¶
type RetryStrategy int
const ( NoRetry RetryStrategy = iota RetryImmediate RetryWithInitialDelay )
func (RetryStrategy) String ¶
func (s RetryStrategy) String() string
String implements the Stringer interface.
type RetryStrategyFn ¶
type RetryStrategyFn func(*http.Response) (RetryStrategy, error)
A RetryStrategyFn is used to determine whether or not a retry is needed, and if so, whether an initial delay is needed or not.