import "github.com/sethgrid/pester"
Package pester provides additional resiliency over the standard http client methods by allowing you to control concurrency, retries, and a backoff strategy.
var DefaultClient = &Client{Concurrency: 1, MaxRetries: 3, Backoff: DefaultBackoff, ErrLog: []ErrEntry{}}
DefaultClient provides sensible defaults
ErrReadingBody happens when we cannot read the body bytes Deprecated: use ErrReadingRequestBody
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
DefaultBackoff always returns 1 second
Do provides the same functionality as http.Client.Do and creates its own constructor
ExponentialBackoff returns ever increasing backoffs by a power of 2
ExponentialJitterBackoff returns ever increasing backoffs by a power of 2 with +/- 0-33% to prevent sychronized reuqests.
Get provides the same functionality as http.Client.Get and creates its own constructor
Head provides the same functionality as http.Client.Head and creates its own constructor
LinearBackoff returns increasing durations, each a second longer than the last
LinearJitterBackoff returns increasing durations, each a second longer than the last with +/- 0-33% to prevent sychronized reuqests.
Post provides the same functionality as http.Client.Post and creates its own constructor
PostForm provides the same functionality as http.Client.PostForm and creates its own constructor
BackoffStrategy is used to determine how long a retry request should wait until attempted
type Client struct { Transport http.RoundTripper CheckRedirect func(req *http.Request, via []*http.Request) error Jar http.CookieJar Timeout time.Duration // pester specific Concurrency int MaxRetries int Backoff BackoffStrategy KeepLog bool LogHook LogHook ContextLogHook ContextLogHook SuccessReqNum int SuccessRetryNum int sync.Mutex 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.
New constructs a new DefaultClient with sensible default values
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.
Do provides the same functionality as http.Client.Do
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
Format the Error to human readable string
Get provides the same functionality as http.Client.Get
Head provides the same functionality as http.Client.Head
LogErrCount is a helper method used primarily for test validation
LogString provides a string representation of the errors the client has seen
func (c *Client) Post(url string, bodyType string, body io.Reader) (resp *http.Response, err error)
Post provides the same functionality as http.Client.Post
PostForm provides the same functionality as http.Client.PostForm
set RetryOnHTTP429 for clients,
Wait blocks until all pester requests have returned Probably not that useful outside of testing.
ContextLogHook does the same as LogHook but with passed Context
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
LogHook is used to log attempts as they happen. This function is never called, however, if KeepLog is set to true.
Path | Synopsis |
---|---|
sample |
Package pester imports 12 packages (graph) and is imported by 67 packages. Updated 2020-06-18. Refresh now. Tools for package owners.