Documentation
¶
Overview ¶
Package middleware provides HTTP middleware components.
Index ¶
Constants ¶
View Source
const ( DefaultMaxRetries = 3 DefaultInitialBackoff = 200 * time.Millisecond DefaultMaxBackoff = 5 * time.Second DefaultBackoffFactor = 2.0 DefaultJitterFactor = 0.2 // 20% jitter )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type RetryConfig ¶
type RetryConfig struct {
// MaxRetries is the maximum number of retry attempts (0 means no retries).
MaxRetries int
// InitialBackoff is the initial delay before the first retry.
InitialBackoff time.Duration
// MaxBackoff is the maximum delay between retries.
MaxBackoff time.Duration
// BackoffFactor is the multiplier applied to backoff after each retry.
BackoffFactor float64
// JitterFactor adds randomness to backoff (0.0-1.0, where 0.2 = ±20%).
JitterFactor float64
// RetryableStatusCodes are HTTP status codes that should trigger a retry.
// If nil, defaults to 429, 500, 502, 503, 504.
RetryableStatusCodes []int
// OnRetry is an optional callback invoked before each retry attempt.
// It receives the attempt number (1-indexed), the response (may be nil), and the error.
OnRetry func(attempt int, resp *http.Response, err error)
}
func DefaultRetryConfig ¶
func DefaultRetryConfig() RetryConfig
func NoRetryConfig ¶
func NoRetryConfig() RetryConfig
type RetryTransport ¶
type RetryTransport struct {
Base http.RoundTripper
Config RetryConfig
}
func NewRetryTransport ¶
func NewRetryTransport(base http.RoundTripper, config RetryConfig) *RetryTransport
Click to show internal directories.
Click to hide internal directories.