Package retry
Overview ▹
Index ▹
Variables
var DefaultRetryer = All(Max(10), Timeout(30*time.Second), EOF(), Over(300))
type Attempt ¶
Attempt counts the round trips issued, starting from 1. Response is valid only when Err is nil.
type Attempt struct { Start time.Time Count uint Err error *http.Request *http.Response }
type Decision ¶
Decision signals the intent of a Retryer
type Decision int
const ( Ignore Decision = iota Retry Abort )
type Delayer ¶
Delayer sleeps or selects any amount of time for each attempt.
type Delayer func(Attempt)
func Constant ¶
func Constant(delta time.Duration) Delayer
Constant sleeps for delta duration
func Exponential ¶
func Exponential(base time.Duration) Delayer
Linear sleeps for delta * 2^attempts
func Fibonacci ¶
func Fibonacci(delta time.Duration) Delayer
Fibonacci sleeps for delta * fib(attempts)
func Linear ¶
func Linear(delta time.Duration) Delayer
Linear sleeps for delta * the number of attempts
type MaxError ¶
MaxError is returned from RoundTrip when the maximum attempts has been reached.
type MaxError struct {
// contains filtered or unexported fields
}
func (MaxError) Error ¶
func (e MaxError) Error() string
type Retryer ¶
Retryer chooses whether or not to retry this request. The error is only valid when the Retyer returns Abort.
type Retryer func(Attempt) (Decision, error)
func All ¶
func All(conditions ...Retryer) Retryer
All aggregates decisions from Retryers for an attempt. All returns Abort and the error on the first Abort. If at least one returns Retry All returns Retry with nil error. Otherwise All returns Ignore with nil error.
func EOF ¶
func EOF() Retryer
EOF retries only when the error is EOF
func Errors ¶
func Errors() Retryer
Errors returns Retry when the attempt produced an error.
func Max ¶
func Max(limit uint) Retryer
Max errors after a limited number of attempts
func Net ¶
func Net() Retryer
Net retries errors returned by the 'net' package.
func Over ¶
func Over(statusCode int) Retryer
Over retries when a response is missing or the status code is over a value like 300
func Temporary ¶
func Temporary() Retryer
Temporary retries if the error implements Temporary() bool and returns true or aborts if returning false.
func Timeout ¶
func Timeout(limit time.Duration) Retryer
Timeout errors after a duration of time passes since the first attempt.
type TimeoutError ¶
TimeoutError is returned from RoundTrip when the time limit has been reached.
type TimeoutError struct {
// contains filtered or unexported fields
}
func (TimeoutError) Error ¶
func (e TimeoutError) Error() string
type Transport ¶
type Transport struct { // Delay is called for attempts that are retried. If nil, no delay will be used. Delay Delayer // Retry is called for every attempt Retry Retryer // Next is called for every attempt Next http.RoundTripper }
func (Transport) RoundTrip ¶
func (t Transport) RoundTrip(req *http.Request) (*http.Response, error)
RoundTrip delegates a RoundTrip, then determines via Retry whether to retry and Delay for the wait time between attempts.