Documentation ¶
Overview ¶
Package pester provides additional resiliency over the standard http client methods by allowing you to control request rates, retries, and a backoff strategy.
Index ¶
- Variables
- func DefaultBackoff(_ int) time.Duration
- func Do(req *http.Request) (resp *http.Response, err error)
- func ExponentialBackoff(i int) time.Duration
- func ExponentialJitterBackoff(i int) time.Duration
- func Get(url string) (resp *http.Response, err error)
- func Head(url string) (resp *http.Response, err error)
- func LinearBackoff(i int) time.Duration
- func LinearJitterBackoff(i int) time.Duration
- func Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
- func PostForm(url string, data url.Values) (resp *http.Response, err error)
- type BackoffStrategy
- type Client
- func (c *Client) Do(req *http.Request) (resp *http.Response, err error)
- func (c *Client) FormatError(e ErrEntry) string
- func (c *Client) Get(url string) (resp *http.Response, err error)
- func (c *Client) Head(url string) (resp *http.Response, err error)
- func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
- func (c *Client) PostForm(url string, data url.Values) (resp *http.Response, err error)
- func (c *Client) SetCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error)
- func (c *Client) SetJar(jar http.CookieJar)
- func (c *Client) SetRetryOnHTTP429(flag bool)
- func (c *Client) SetTimeout(timeout time.Duration)
- func (c *Client) SetTransport(transport http.RoundTripper)
- type ContextLogHook
- type ErrEntry
- type LogHook
- type ResponseError
Constants ¶
This section is empty.
Variables ¶
var ( // ErrUnexpectedMethod occurs when an http.Client method is unable to be mapped from a calling method in the pester client ErrUnexpectedMethod = errors.New("unexpected client method, must be one of Do, Get, Head, Post, or PostFrom") // ErrReadingBody happens when we cannot read the body bytes // Deprecated: use ErrReadingRequestBody ErrReadingBody = errors.New("error reading body") // ErrReadingRequestBody happens when we cannot read the request body bytes ErrReadingRequestBody = errors.New("error reading request body") )
var DefaultClient = &Client{MaxRetries: 3, Backoff: DefaultBackoff, ErrLog: []ErrEntry{}}
Functions ¶
func DefaultBackoff ¶
DefaultBackoff always returns 1 second
func ExponentialBackoff ¶
ExponentialBackoff returns ever increasing backoffs by a power of 2
func ExponentialJitterBackoff ¶
ExponentialJitterBackoff returns ever increasing backoffs by a power of 2 with +/- 0-33% to prevent sychronized reuqests.
func Head ¶
Head provides the same functionality as http.Client.Head and creates its own constructor
func LinearBackoff ¶
LinearBackoff returns increasing durations, each a second longer than the last
func LinearJitterBackoff ¶
LinearJitterBackoff returns increasing durations, each a second longer than the last with +/- 0-33% to prevent sychronized reuqests.
Types ¶
type BackoffStrategy ¶
BackoffStrategy is used to determine how long a retry request should wait until attempted
type Client ¶
type Client struct { Ratelimiter *rate.Limiter // pester specific MaxRetries int Backoff BackoffStrategy LogHook LogHook ContextLogHook ContextLogHook ErrLog []ErrEntry RetryOnHTTP429 bool // contains filtered or unexported fields }
Client wraps the http client and exposes all the functionality of the http.Client. Additionally, Client provides pester specific values for handling resiliency.
func (*Client) FormatError ¶
Format the Error to human readable string
func (*Client) SetCheckRedirect ¶
func (*Client) SetRetryOnHTTP429 ¶
set RetryOnHTTP429 for clients,
func (*Client) SetTimeout ¶
func (*Client) SetTransport ¶
func (c *Client) SetTransport(transport http.RoundTripper)
type ContextLogHook ¶
ContextLogHook does the same as LogHook but with passed Context
type ErrEntry ¶
type ErrEntry struct { Time time.Time Method string URL string Verb string Request int Retry int Attempt int Err error }
ErrEntry is used to provide the LogString() data and is populated each time an error happens if KeepLog is set. ErrEntry.Retry is deprecated in favor of ErrEntry.Attempt