Documentation
¶
Index ¶
- func New(opts ...Option) *http.Transport
- func NewHeader(provider HeaderProvider) func(http.RoundTripper) http.RoundTripper
- func NewHedger(backoffPolicy BackoffPolicy) func(http.RoundTripper) http.RoundTripper
- func NewRetrier(backoffPolicy BackoffPolicy, retryPolicies ...RetryPolicy) func(http.RoundTripper) http.RoundTripper
- func OptionDefaultTransport(t *http.Transport) *http.Transport
- type BackoffPolicy
- type Backoffer
- type Chain
- type Decorator
- type Factory
- type FixedBackoffer
- type Header
- type HeaderProvider
- type Hedger
- type LimitedRetrier
- type Option
- func OptionDial(dial func(network, addr string) (net.Conn, error)) Option
- func OptionDialContext(dialCtx func(ctx context.Context, network, addr string) (net.Conn, error)) Option
- func OptionDialTLS(dial func(network, addr string) (net.Conn, error)) Option
- func OptionDisableCompression(disabled bool) Option
- func OptionDisableKeepAlives(disabled bool) Option
- func OptionExpectContinueTimeout(timeout time.Duration) Option
- func OptionIdleConnTimeout(timeout time.Duration) Option
- func OptionMaxIdleConns(max int) Option
- func OptionMaxIdleConnsPerHost(max int) Option
- func OptionMaxResponseHeaderBytes(max int64) Option
- func OptionProxy(proxy func(*http.Request) (*url.URL, error)) Option
- func OptionProxyConnectHeader(header http.Header) Option
- func OptionResponseHeaderTimeout(timeout time.Duration) Option
- func OptionTLSClientConfig(config *tls.Config) Option
- func OptionTLSHandshakeTimeout(timeout time.Duration) Option
- func OptionTLSNextProto(next map[string]func(authority string, c *tls.Conn) http.RoundTripper) Option
- type PercentJitteredBackoffer
- type RecycleOption
- type Recycler
- type Requester
- type Retrier
- type Retry
- type RetryPolicy
- type Rotator
- type RotatorOption
- type RoundTripperFunc
- type StatusCodeRetrier
- type TimeoutRetrier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewHeader ¶
func NewHeader(provider HeaderProvider) func(http.RoundTripper) http.RoundTripper
NewHeader wraps a transport in order to include custom headers.
func NewHedger ¶
func NewHedger(backoffPolicy BackoffPolicy) func(http.RoundTripper) http.RoundTripper
NewHedger configures a RoundTripper decorator to perform some number of hedged requests.
func NewRetrier ¶
func NewRetrier(backoffPolicy BackoffPolicy, retryPolicies ...RetryPolicy) func(http.RoundTripper) http.RoundTripper
NewRetrier configures a RoundTripper decorator to perform some number of retries.
Types ¶
type BackoffPolicy ¶
type BackoffPolicy func() Backoffer
BackoffPolicy is a factory that generates a Backoffer.
func NewFixedBackoffPolicy ¶
func NewFixedBackoffPolicy(wait time.Duration) BackoffPolicy
NewFixedBackoffPolicy generates a BackoffPolicy that always returns the same value.
func NewPercentJitteredBackoffPolicy ¶
func NewPercentJitteredBackoffPolicy(wrapped BackoffPolicy, jitterPercent float64) BackoffPolicy
NewPercentJitteredBackoffPolicy wraps any backoff policy and applies a percentage based jitter to the original policy's value. The percentage float should be between 0 and 1. The jitter will be applied as a positive and negative value equally.
type Chain ¶
type Chain []Decorator
Chain is an ordered collection of Decorators.
func (Chain) Apply ¶
func (c Chain) Apply(base http.RoundTripper) http.RoundTripper
Apply wraps the given RoundTripper with the Decorator chain.
func (Chain) ApplyFactory ¶
ApplyFactory wraps the given Factory such that all new instances produced will be decorated with the contents of the chain.
type Decorator ¶
type Decorator func(http.RoundTripper) http.RoundTripper
Decorator is a named type for any function that takes a RoundTripper and returns a RoundTripper.
type Factory ¶
type Factory func() http.RoundTripper
Factory is any function that takes no arguments and returns a Transport.
func NewFactory ¶
NewFactory returns a Factory that is bound to the given Option set.
func NewRecyclerFactory ¶
func NewRecyclerFactory(factory Factory, opts ...RecycleOption) Factory
NewRecyclerFactory is a counterpart for NewRecycler that generates a Factory function for use with other decorators.
func NewRotatorFactory ¶
func NewRotatorFactory(factory Factory, opts ...RotatorOption) Factory
NewRotatorFactory is a counterpart for NewRotator that generates a Factory function for use with other decorators.
type FixedBackoffer ¶
type FixedBackoffer struct {
// contains filtered or unexported fields
}
FixedBackoffer signals the client to wait for a static amount of time.
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is a decorator that injects a header value into every request.
type HeaderProvider ¶
HeaderProvider is mapping function that generates the required header name and value from an outgoing request.
type Hedger ¶
type Hedger struct {
// contains filtered or unexported fields
}
Hedger is a wrapper that fans out a new request at each time interval defined by the backoff policy, and returns the first response received. For latency-based retries, this will often be a better approach than a "stop-and-retry" policy (such as the TimeoutRetrier). The hedging decorator allows for a worst case request to take up to a maximum configurable timeout, while pessimistically creating new requests before the timeout is reached.
type LimitedRetrier ¶
type LimitedRetrier struct {
// contains filtered or unexported fields
}
LimitedRetrier wraps a series of retry policies in a hard upper limit.
type Option ¶
Option is a function that either modifies or generates a new Transport.
func OptionDial ¶
OptionDial installs a custom Dial configuration in the Transport.
func OptionDialContext ¶
func OptionDialContext(dialCtx func(ctx context.Context, network, addr string) (net.Conn, error)) Option
OptionDialContext installs a custom DialContext configuration in the Transport.
func OptionDialTLS ¶
OptionDialTLS installs a custom DialTLS configuration in the Transport.
func OptionDisableCompression ¶
OptionDisableCompression installs a custom DisableCompression option in the Transport.
func OptionDisableKeepAlives ¶
OptionDisableKeepAlives installs a custom DisableKeepAlives option in the Transport.
func OptionExpectContinueTimeout ¶
OptionExpectContinueTimeout installs a custom ExpectContinueTimeout option in the Transport.
func OptionIdleConnTimeout ¶
OptionIdleConnTimeout installs a custom IdleConnTimeout option in the Transport.
func OptionMaxIdleConns ¶
OptionMaxIdleConns installs a custom MaxIdleConns option in the Transport.
func OptionMaxIdleConnsPerHost ¶
OptionMaxIdleConnsPerHost installs a custom MaxIdleConnsPerHost option in the Transport.
func OptionMaxResponseHeaderBytes ¶
OptionMaxResponseHeaderBytes installs a custom MaxResponseHeaderBytes option in the Transport.
func OptionProxy ¶
OptionProxy installs a custom Proxy configuration in the Transport.
func OptionProxyConnectHeader ¶
OptionProxyConnectHeader installs a custom ProxyConnectHeader option in the Transport.
func OptionResponseHeaderTimeout ¶
OptionResponseHeaderTimeout installs a custom ResponseHeaderTimeout option in the Transport.
func OptionTLSClientConfig ¶
OptionTLSClientConfig installs a custom TLSClientConfig in the Transport.
func OptionTLSHandshakeTimeout ¶
OptionTLSHandshakeTimeout installs a custom TLSHandshakeTimeout in the Transport.
func OptionTLSNextProto ¶
func OptionTLSNextProto(next map[string]func(authority string, c *tls.Conn) http.RoundTripper) Option
OptionTLSNextProto installs a custom TLSNextProto option in the Transport.
type PercentJitteredBackoffer ¶
type PercentJitteredBackoffer struct {
// contains filtered or unexported fields
}
PercentJitteredBackoffer adjusts the backoff time by a random amount within N percent of the duration to help with thundering herds.
type RecycleOption ¶
RecycleOption is a configuration for the Recycler decorator
func RecycleOptionChannel ¶
func RecycleOptionChannel(signal chan struct{}) RecycleOption
RecycleOptionChannel configures the recycler to rotate based on input from a channel.
func RecycleOptionMaxUsage ¶
func RecycleOptionMaxUsage(max int) RecycleOption
RecycleOptionMaxUsage configures the recycler to rotate Transports after a number of uses.
func RecycleOptionTTL ¶
func RecycleOptionTTL(ttl time.Duration) RecycleOption
RecycleOptionTTL configures the recycler to rotate Transports on an interval.
func RecycleOptionTTLJitter ¶
func RecycleOptionTTLJitter(jitter time.Duration) RecycleOption
RecycleOptionTTLJitter adds a randomised jitter to the TTL that is plus or minus the duration value given.
type Recycler ¶
type Recycler struct {
// contains filtered or unexported fields
}
Recycler is a decorator that discards and regenerates the transport after a given set of triggers.
func NewRecycler ¶
func NewRecycler(factory Factory, opts ...RecycleOption) *Recycler
NewRecycler uses the given factory as a source and recycles the transport based on the options given.
type Requester ¶
Requester can be implemented if the Retrier needs to manipulate the request or request context before it is executed.
type Retry ¶
type Retry struct {
// contains filtered or unexported fields
}
Retry is a wrapper for applying various retry policies to requests.
type RetryPolicy ¶
type RetryPolicy func() Retrier
RetryPolicy is a factory that generates a Retrier.
func NewLimitedRetryPolicy ¶
func NewLimitedRetryPolicy(limit int, policies ...RetryPolicy) RetryPolicy
NewLimitedRetryPolicy wraps a series of retry policies in an upper limit.
func NewStatusCodeRetryPolicy ¶
func NewStatusCodeRetryPolicy(codes ...int) RetryPolicy
NewStatusCodeRetryPolicy generates a RetryPolicy that retries on specified status codes in the HTTP response.
func NewTimeoutRetryPolicy ¶
func NewTimeoutRetryPolicy(timeout time.Duration) RetryPolicy
NewTimeoutRetryPolicy generates a RetryPolicy that ends a request after a given timeout duration and tries again.
type Rotator ¶
type Rotator struct {
// contains filtered or unexported fields
}
Rotator contains multiple instances of a RoundTripper and rotates through them per-request. This is useful when dealing with HTTP/2 in situations where more than one TCP connection per host is required.
func NewRotator ¶
func NewRotator(factory Factory, opts ...RotatorOption) *Rotator
NewRotator uses the given factory as a source and generates a number of instances based on the options given. The instances are called in a naive, round-robin manner.
type RotatorOption ¶
RotatorOption is a configuration for the Rotator decorator
func RotatorOptionInstances ¶
func RotatorOptionInstances(number int) RotatorOption
RotatorOptionInstances configurs a rotator with the number of internal RoundTripper instances it should maintain for the rotation.
type RoundTripperFunc ¶
RoundTripperFunc is modelled after the http.HandlerFunc and converts a function matching the RoundTrip signature to a RoundTripper implementation.
type StatusCodeRetrier ¶
type StatusCodeRetrier struct {
// contains filtered or unexported fields
}
StatusCodeRetrier retries based on HTTP status codes.
type TimeoutRetrier ¶
type TimeoutRetrier struct {
// contains filtered or unexported fields
}
TimeoutRetrier applies a timeout to requests and retries if the request took longer than the timeout duration.