retry

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jun 26, 2025 License: MIT Imports: 6 Imported by: 5

README

retry

Simple retry package to get a retryable *http.Client or http.RoundTripper that wraps github.com/cenkalti/backoff/v5.

How to use

You can customise retry.Config as documented.

Retryable http.Client
import (
    "github.com/smithy-security/pkg/retry"
)

...

client, err := retry.NewClient(retry.Config{
	MaxRetries: 10,
})
...
Retryable http.RoundTripper
import (
    "github.com/smithy-security/pkg/retry"
)

...

rt, err := retry.NewRoundTripper(retry.Config{
	MaxRetries: 10,
})
...

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewClient

func NewClient(config Config) (*http.Client, error)

NewClient returns a new http.Client with retry behaviour.

func NewRoundTripper

func NewRoundTripper(config Config) (http.RoundTripper, error)

NewRoundTripper returns a new http.RoundTripper with retry behaviour.

Types

type Config

type Config struct {
	BaseClient *http.Client
	// BaseTransport allows to specify a base http.RoundTripper.
	BaseTransport http.RoundTripper
	// Logger allows to specify a custom logger. *slog.Logger will satisfy this.
	Logger Logger
	// NextRetryInSecondsFunc allows to specify a custom retry function.
	// By default, exponential fibonacci like function is used.
	NextRetryInSecondsFunc NextRetryInSeconds
	// MaxRetries allows to specify the number of max retries before returning a fatal error.
	// 5 is the default.
	MaxRetries uint
	// RetryableStatusCodes allows to specify the retryable status codes.
	// defaultRetryableStatusCodes are the default.
	RetryableStatusCodes map[int]struct{}
	// AcceptedStatusCodes allows to specify the non-retryable status codes.
	// defaultAcceptedStatusCodes are the default.
	AcceptedStatusCodes map[int]struct{}
}

Config allows configuring the client.

func (Config) Validate

func (c Config) Validate() error

Validate validates the client configuration.

type Logger

type Logger interface {
	Error(msg string, keysAndValues ...interface{})
	Info(msg string, keysAndValues ...interface{})
	Debug(msg string, keysAndValues ...interface{})
	Warn(msg string, keysAndValues ...interface{})
}

Logger allows to inject a custom logger in the client.

type NextRetryInSeconds

type NextRetryInSeconds func(currAttempt uint) int

NextRetryInSeconds allows customising the behaviour for the calculating the next retry.

Jump to

Keyboard shortcuts

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