backoff

package
v8.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2025 License: Apache-2.0 Imports: 4 Imported by: 2

Documentation

Overview

Package backoff provides exponential backoff retry logic.

Index

Constants

View Source
const (
	DefaultMaxRetries    = 3
	DefaultRetryInterval = 2 * time.Second
	DefaultMaxInterval   = 30 * time.Second
)

Default configuration values.

Variables

This section is empty.

Functions

func Retry

func Retry(fn func() error, opts ...Option) error

Retry executes the provided function with retry logic using exponential backoff.

Types

type Option

type Option func(*Options)

Option is a function that applies an option to an Options instance.

func WithMaxInterval

func WithMaxInterval(i time.Duration) Option

WithMaxInterval sets the maximum interval between retry attempts.

func WithMaxRetries

func WithMaxRetries(n int) Option

WithMaxRetries sets the maximum number of retry attempts.

func WithRetryInterval

func WithRetryInterval(i time.Duration) Option

WithRetryInterval sets the initial interval between retry attempts.

type Options

type Options struct {
	// MaxRetries is the maximum number of retry attempts.
	// Default is 3.
	MaxRetries int `json:"gmt_max_retries" mapstructure:"gmt_max_retries"`

	// Interval is the initial interval between retry attempts.
	// Default is 2 seconds.
	Interval time.Duration `json:"gmt_retry_interval" mapstructure:"gmt_retry_interval"`

	// MaxInterval is the maximum interval between retry attempts.
	// Default is 30 seconds.
	MaxInterval time.Duration `json:"gmt_retry_max_interval" mapstructure:"gmt_retry_max_interval"`
}

Options is the configuration options for retry operations.

Jump to

Keyboard shortcuts

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