Documentation
¶
Overview ¶
Package retry provides shared retry, backoff, and rate-limiting logic.
Index ¶
Constants ¶
const ( // DefaultMaxRetries is the default number of retry attempts. DefaultMaxRetries = 3 // DefaultBaseDelay is the default initial backoff delay. DefaultBaseDelay = time.Second // DefaultMaxDelay is the default maximum backoff delay. DefaultMaxDelay = 30 * time.Second )
Variables ¶
This section is empty.
Functions ¶
func IsRetryable ¶
IsRetryable returns true for common transient network errors. Protocol-specific checks (SMTP 4xx, IMAP auth) should be combined with this in a wrapper that also checks protocol-specific conditions.
func WaitForToken ¶
WaitForToken blocks until a rate limit token is available or ctx is canceled.
func WithRetry ¶
func WithRetry( ctx context.Context, cfg Config, lim *Limiter, isRetryable IsRetryableFunc, op func() error, ) error
WithRetry executes op with rate limiting, exponential backoff, and jitter. The isRetryable function determines whether a failed attempt should be retried. If lim is non-nil, a rate limit token is acquired before each attempt.
Types ¶
type Config ¶
type Config struct {
MaxRetries int
BaseDelay time.Duration
MaxDelay time.Duration
RateLimit int // tokens per window
RateWindow time.Duration // window duration
}
Config controls retry behavior.
type IsRetryableFunc ¶
IsRetryableFunc classifies whether an error is transient.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter implements a token-bucket rate limiter with a sliding window.
func NewLimiter ¶
NewLimiter creates a rate limiter with the given token limit and window duration.
type PermanentError ¶
type PermanentError struct {
Err error
}
PermanentError wraps an error to signal that it should not be retried, regardless of what the IsRetryableFunc says. Use this for errors like failed reconnections that should immediately abort the retry loop.
func (*PermanentError) Error ¶
func (e *PermanentError) Error() string
func (*PermanentError) Unwrap ¶
func (e *PermanentError) Unwrap() error