retry

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, config Config, fn func() error) error

Do executes a function with retry logic

func DoWithResponse

func DoWithResponse(ctx context.Context, config Config, fn func() (*http.Response, error)) (*http.Response, error)

DoWithResponse executes an HTTP request with retry logic and respects Retry-After headers

func IsRetriable

func IsRetriable(err error) bool

IsRetriable determines if an error is retriable

Types

type Config

type Config struct {
	// MaxRetries is the maximum number of retry attempts
	MaxRetries int
	// InitialDelay is the initial delay before the first retry
	InitialDelay time.Duration
	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration
	// Multiplier is the factor by which the delay increases each retry
	Multiplier float64
	// Jitter adds randomness to delay to prevent thundering herd
	Jitter bool
}

Config holds retry configuration parameters

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default retry configuration

func (Config) Backoff

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

Backoff calculates the delay for a given retry attempt

Jump to

Keyboard shortcuts

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