Documentation ¶
Index ¶
Constants ¶
View Source
const ( // RetryTimes defines the default max amount of times to retry a request. RetryTimes = 3 // RetryWait defines the default amount of time to wait before each retry attempt. RetryWait = 100 * time.Millisecond )
View Source
const Version = "2.0.1"
Version defines the package semantic version
Variables ¶
View Source
var ( // ConstantBackoff provides a built-in retry strategy based on constant back off. ConstantBackoff = retry.New(retry.ConstantBackoff(RetryTimes, RetryWait), nil) // ExponentialBackoff provides a built-int retry strategy based on exponential back off. ExponentialBackoff = retry.New(retry.ExponentialBackoff(RetryTimes, RetryWait), nil) )
View Source
var ( // ErrServer stores the error when a server error happens. ErrServer = errors.New("retry: server response error") )
View Source
var Evaluator = func(err error, res *http.Response, req *http.Request) error { if err != nil { return err } if res.StatusCode >= 500 || res.StatusCode == 429 { return ErrServer } return nil }
Evaluator determines when a request failed in order to retry it, evaluating the error, response and optionally the original request.
By default if will retry if an error is present or response status code is >= 500.
You can override this function to use a custom evaluator function with additional logic.
Functions ¶
func InterceptTransport ¶
InterceptTransport is a middleware function handler that intercepts the HTTP transport based on the given HTTP retrier and context.
Types ¶
Click to show internal directories.
Click to hide internal directories.