retry

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides retry logic with exponential backoff and jitter.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ShouldRetry

func ShouldRetry(err error, statusCode int) bool

ShouldRetry determines if a request should be retried based on the error or status code.

func Wait

func Wait(ctx context.Context, duration time.Duration) error

Wait waits for the backoff duration, respecting context cancellation.

Types

type Config

type Config struct {
	// MaxRetries is the maximum number of retry attempts.
	MaxRetries int
	// BaseDelay is the initial delay before the first retry.
	BaseDelay time.Duration
	// MaxDelay is the maximum delay between retries.
	MaxDelay time.Duration
	// Multiplier is the factor by which the delay increases after each retry.
	Multiplier float64
}

Config holds configuration for the retry mechanism.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default retry configuration.

func (Config) Backoff

func (c Config) Backoff(attempt int) time.Duration

Backoff calculates the delay for the next retry attempt using exponential backoff with jitter.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL