Documentation ¶
Overview ¶
Package pester provides additional resiliency over the standard http client methods by allowing you to control concurrency, 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) EmbedHTTPClient(hc *http.Client)
- 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) LogErrCount() int
- func (c *Client) LogString() string
- 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) SetRetryOnHTTP429(flag bool)
- type ErrEntry
- type LogHook
Constants ¶
This section is empty.
Variables ¶
var DefaultClient = &Client{MaxRetries: 3, Backoff: DefaultBackoff, ErrLog: []ErrEntry{}}
DefaultClient provides sensible defaults
var ErrReadingBody = errors.New("error reading body")
ErrReadingBody happens when we cannot read the body bytes
var ErrReadingRequestBody = errors.New("error reading request body")
ErrReadingRequestBody happens when we cannot read the request body bytes
var ErrUnexpectedMethod = errors.New("unexpected client method, must be one of Do, Get, Head, Post, or PostFrom")
ErrUnexpectedMethod occurs when an http.Client method is unable to be mapped from a calling method in the pester client
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 { Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error Jar http.CookieJar Timeout time.Duration // pester specific MaxRetries int Backoff BackoffStrategy KeepLog bool LogHook LogHook RetryAttemptHeader string 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 NewExtendedClient ¶
NewExtendedClient allows you to pass in an http.Client that is previously set up and extends it to have Pester's features of concurrency and retries.
func (*Client) EmbedHTTPClient ¶
EmbedHTTPClient allows you to extend an existing Pester client with an underlying http.Client, such as https://godoc.org/golang.org/x/oauth2/google#DefaultClient
func (*Client) FormatError ¶
FormatError formats the Error to human readable string
func (*Client) LogErrCount ¶
LogErrCount is a helper method used primarily for test validation
func (*Client) LogString ¶
LogString provides a string representation of the errors the client has seen
func (*Client) SetRetryOnHTTP429 ¶
SetRetryOnHTTP429 sets RetryOnHTTP429 for clients