Documentation ¶
Index ¶
- Constants
- type TransportWrapper
- type TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Build(ctx context.Context) (result *TransportWrapper, err error)
- func (b *TransportWrapperBuilder) Interval(value time.Duration) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Jitter(value float64) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Limit(value int) *TransportWrapperBuilder
- func (b *TransportWrapperBuilder) Logger(value logging.Logger) *TransportWrapperBuilder
Constants ¶
const ( DefaultLimit = 2 DefaultInterval = 1 * time.Second DefaultJitter = 0.2 )
Default configuration:
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type TransportWrapper ¶
type TransportWrapper struct {
// contains filtered or unexported fields
}
TransportWrapper contains the data and logic needed to wrap an HTTP round tripper with another one that adds retry capability.
func (*TransportWrapper) Close ¶
func (w *TransportWrapper) Close() error
Close releases all the resources used by the wrapper.
func (*TransportWrapper) Interval ¶
func (w *TransportWrapper) Interval() time.Duration
Interval returns the initial retry interval.
func (*TransportWrapper) Jitter ¶
func (w *TransportWrapper) Jitter() float64
Jitter returns the retry interval jitter factor.
func (*TransportWrapper) Limit ¶
func (w *TransportWrapper) Limit() int
Limit returns the maximum number of retries.
func (*TransportWrapper) Wrap ¶
func (w *TransportWrapper) Wrap(transport http.RoundTripper) http.RoundTripper
Wrap creates a new round tripper that wraps the given one and implements the retry logic.
type TransportWrapperBuilder ¶
type TransportWrapperBuilder struct {
// contains filtered or unexported fields
}
TransportWrapperBuilder contains the data and logic needed to create a new retry transport wrapper.
func NewTransportWrapper ¶
func NewTransportWrapper() *TransportWrapperBuilder
NewTransportWrapper creates a new builder that can then be used to configure and create a new retry round tripper.
func (*TransportWrapperBuilder) Build ¶
func (b *TransportWrapperBuilder) Build(ctx context.Context) (result *TransportWrapper, err error)
Build uses the information stored in the builder to create a new transport wrapper.
func (*TransportWrapperBuilder) Interval ¶
func (b *TransportWrapperBuilder) Interval(value time.Duration) *TransportWrapperBuilder
Interval sets the time to wait before the first retry. The interval time will be doubled for each retry. For example, if this is set to one second then the first retry will happen approximately one second after the failure of the initial request, the second retry will happen affer four seconds, the third will happen after eitght seconds, so on.
func (*TransportWrapperBuilder) Jitter ¶
func (b *TransportWrapperBuilder) Jitter(value float64) *TransportWrapperBuilder
Jitter sets a factor that will be used to randomize the retry intervals. For example, if this is set to 0.1 then a random adjustment between -10% and +10% will be done to the interval for each retry. This is intended to reduce simultaneous retries by clients when a server starts failing. The default value is 0.2.
func (*TransportWrapperBuilder) Limit ¶
func (b *TransportWrapperBuilder) Limit(value int) *TransportWrapperBuilder
Limit sets the maximum number of retries for a request. When this is zero no retries will be performed. The default value is two.
func (*TransportWrapperBuilder) Logger ¶
func (b *TransportWrapperBuilder) Logger(value logging.Logger) *TransportWrapperBuilder
Logger sets the logger that will be used by the wrapper and by the round trippers that it creates.