Documentation ¶
Index ¶
- func ConstantBackoffGenerator(d time.Duration) func() backoff.BackOff
- func ExponentialBackoffGenerator(opts ...ExponentialBackoffOption) func() backoff.BackOff
- func NoBackoffGenerator() func() backoff.BackOff
- type BackoffGenerator
- type Client
- func (c *Client) Connect(ctx context.Context, url string, body io.Reader) (*http.Response, error)
- func (c *Client) Delete(ctx context.Context, url string) (*http.Response, error)
- func (c *Client) Get(ctx context.Context, url string) (*http.Response, error)
- func (c *Client) Head(ctx context.Context, url string) (*http.Response, error)
- func (c *Client) Options(ctx context.Context, url string) (*http.Response, error)
- func (c *Client) Patch(ctx context.Context, url string, body io.Reader) (*http.Response, error)
- func (c *Client) Post(ctx context.Context, url string, body io.Reader) (*http.Response, error)
- func (c *Client) Put(ctx context.Context, url string, body io.Reader) (*http.Response, error)
- func (c *Client) Trace(ctx context.Context, url string) (*http.Response, error)
- type ClientConfig
- type ClientOption
- type DefaultRetryPolicy
- type ExponentialBackoffOption
- type OAUTHConfig
- type OAUTHOption
- type OAUTHWrapper
- type RetryPolicy
- type RetryWrapper
- type RetryWrapperConfig
- type RetryWrapperOption
- type TransportWrapper
- type WithAccessToken
- type WithBackoffGenerator
- type WithInitialInterval
- type WithLogger
- type WithMaxElapsedTime
- type WithMaxRetries
- type WithMultiplier
- type WithRandomizationFactor
- type WithTransport
- type WithWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConstantBackoffGenerator ¶
ConstantBackoffGenerator returns a backoff with constant intervals between retries as set with the parameter 'd'.
func ExponentialBackoffGenerator ¶
func ExponentialBackoffGenerator(opts ...ExponentialBackoffOption) func() backoff.BackOff
ExponentialBackoffGenerator returns an ExponentialBackoff instance.
func NoBackoffGenerator ¶
func NoBackoffGenerator() func() backoff.BackOff
NoBackoffGenerator returns a backoff which has no time interval between retries.
Types ¶
type BackoffGenerator ¶
type BackoffGenerator func() backoff.BackOff
BackoffGenerator always returns a new instance of backoff.Backoff to ensure a fresh backoff state for repeated reqeusts
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
NewClient returns an opionanted HTTP client which can be optionally augmented with TransportWrappers which add features such as retries with exponential backoff.
func (*Client) Connect ¶
Connect performs a HTTP CONNECT request against the provided URL with the given body.
func (*Client) Patch ¶
Patch performs a HTTP PATCH request against the provided URL with the given body.
func (*Client) Post ¶
Post performs a HTTP POST request against the provided URL with the given body.
type ClientConfig ¶
type ClientConfig struct { Transport http.RoundTripper Wrappers []TransportWrapper }
func (*ClientConfig) Default ¶
func (c *ClientConfig) Default()
func (*ClientConfig) Option ¶
func (c *ClientConfig) Option(opts ...ClientOption)
func (*ClientConfig) Wrap ¶
func (c *ClientConfig) Wrap(client *http.Client)
type ClientOption ¶
type ClientOption interface {
ConfigureClient(*ClientConfig)
}
type DefaultRetryPolicy ¶
type DefaultRetryPolicy struct{}
func NewDefaultRetryPolicy ¶
func NewDefaultRetryPolicy() DefaultRetryPolicy
NewDefaultRetryPolicy returns the default retry policy implementation.
func (DefaultRetryPolicy) IsErrorRetryable ¶
func (p DefaultRetryPolicy) IsErrorRetryable(err error) bool
func (DefaultRetryPolicy) IsStatusRetryableForMethod ¶
func (p DefaultRetryPolicy) IsStatusRetryableForMethod(method string, code int) bool
type ExponentialBackoffOption ¶
type ExponentialBackoffOption interface {
ConfigureExponentialBackoff(*backoff.ExponentialBackOff)
}
type OAUTHConfig ¶
type OAUTHConfig struct {
// contains filtered or unexported fields
}
func (*OAUTHConfig) Option ¶
func (c *OAUTHConfig) Option(opts ...OAUTHOption)
type OAUTHOption ¶
type OAUTHOption interface {
ConfigureOAUTH(*OAUTHConfig)
}
type OAUTHWrapper ¶
type OAUTHWrapper struct {
// contains filtered or unexported fields
}
func NewOAUTHWrapper ¶
func NewOAUTHWrapper(opts ...OAUTHOption) *OAUTHWrapper
NewOAUTHWrapper returns a TransportWrapper which adds OAUTH2 authentication to a HTTP transport.
func (*OAUTHWrapper) Wrap ¶
func (w *OAUTHWrapper) Wrap(rt http.RoundTripper) http.RoundTripper
type RetryPolicy ¶
type RetryPolicy interface { // IsErrorRetryable determines which url.Error // instances can be retried. IsErrorRetryable(error) bool // IsStatusRetryableForMethod accepts a HTTP method // name and a status code and returns 'true' if a // given combination of the aforementioned parameters // should be retried. IsStatusRetryableForMethod(string, int) bool }
RetryPolicy configures a RetryWrapper's logic to determine when a HTTP request is retryable.
type RetryWrapper ¶
type RetryWrapper struct {
// contains filtered or unexported fields
}
func NewRetryWrapper ¶
func NewRetryWrapper(opts ...RetryWrapperOption) *RetryWrapper
NewRetryWrapper returns a TransportWrapper which detects whether a HTTP request should be retried given a particular failure scenario. A variadic slice of options can be provided to configure the retry behavior from default.
func (*RetryWrapper) Wrap ¶
func (w *RetryWrapper) Wrap(rt http.RoundTripper) http.RoundTripper
type RetryWrapperConfig ¶
type RetryWrapperConfig struct { Logger logr.Logger GenerateBackoff func() backoff.BackOff Policy RetryPolicy // contains filtered or unexported fields }
func (*RetryWrapperConfig) Default ¶
func (c *RetryWrapperConfig) Default()
func (*RetryWrapperConfig) Option ¶
func (c *RetryWrapperConfig) Option(opts ...RetryWrapperOption)
type RetryWrapperOption ¶
type RetryWrapperOption interface {
ConfigureRetryWrapper(*RetryWrapperConfig)
}
type TransportWrapper ¶
type TransportWrapper interface { // Wrap return a http.RoundTripper which has been // wrapped with the pre and post functionality the // TransportWrapper provides. Wrap(http.RoundTripper) http.RoundTripper }
TransportWrapper adds functionality to a http.RoundTripper by adding pre and post call execution steps.
type WithAccessToken ¶
type WithAccessToken string
WithAccessToken configures a OAUTHWrapper with an OAUTH2 token used when making requests.
func (WithAccessToken) ConfigureOAUTH ¶
func (at WithAccessToken) ConfigureOAUTH(c *OAUTHConfig)
type WithBackoffGenerator ¶
type WithBackoffGenerator func() backoff.BackOff
WithBackoffGenerator configures a RetryWrapper instance with the provided BackoffGenerator.
func (WithBackoffGenerator) ConfigureRetryWrapper ¶
func (bg WithBackoffGenerator) ConfigureRetryWrapper(c *RetryWrapperConfig)
type WithInitialInterval ¶
WithInitialInterval sets the wait time between the first and second request attempts.
func (WithInitialInterval) ConfigureExponentialBackoff ¶
func (w WithInitialInterval) ConfigureExponentialBackoff(bo *backoff.ExponentialBackOff)
type WithLogger ¶
WithLogger configures a RetryWrapper instance with the provided logr.Logger instance.
func (WithLogger) ConfigureRetryWrapper ¶
func (l WithLogger) ConfigureRetryWrapper(c *RetryWrapperConfig)
type WithMaxElapsedTime ¶
WithMaxElapsedTime sets the maximum cumulative time after which retries are no longer performed.
func (WithMaxElapsedTime) ConfigureExponentialBackoff ¶
func (w WithMaxElapsedTime) ConfigureExponentialBackoff(bo *backoff.ExponentialBackOff)
type WithMaxRetries ¶
type WithMaxRetries uint64
WithMaxRetries sets the maximum retry attempts for a RetryWrapper instance.
func (WithMaxRetries) ConfigureRetryWrapper ¶
func (mr WithMaxRetries) ConfigureRetryWrapper(c *RetryWrapperConfig)
type WithMultiplier ¶
type WithMultiplier float64
WithMultiplier sets the exponential base used for increasing backoff.
func (WithMultiplier) ConfigureExponentialBackoff ¶
func (w WithMultiplier) ConfigureExponentialBackoff(bo *backoff.ExponentialBackOff)
type WithRandomizationFactor ¶
type WithRandomizationFactor float64
WithRandomizationFactor sets the degree to which jitter is applied to successive retries.
func (WithRandomizationFactor) ConfigureExponentialBackoff ¶
func (w WithRandomizationFactor) ConfigureExponentialBackoff(bo *backoff.ExponentialBackOff)
type WithTransport ¶
type WithTransport struct{ http.RoundTripper }
WithTransport configures a Client instance with the given http.RoundTripper instance.
func (WithTransport) ConfigureClient ¶
func (t WithTransport) ConfigureClient(c *ClientConfig)
type WithWrapper ¶
type WithWrapper struct{ TransportWrapper }
WithWrapper configures a Client instance with the given TransportWrapper. This option can be provided multiple times to apply several TransportWrappers. The order in which the TransportWrappers is applied is important!
func (WithWrapper) ConfigureClient ¶
func (ww WithWrapper) ConfigureClient(c *ClientConfig)