retry

package
v2.0.0-...-1c13370 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides an implementation for retrying http requests with multiple wait strategies

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*OptionsData)

Option is the interface for defining Options

func WithMaxRetry

func WithMaxRetry(max int) Option

WithMaxRetry set the max number of times a request is tried

func WithRetryAllMethods

func WithRetryAllMethods(retryAllMethods bool) Option

WithRetryAllMethods sets retry on all HTTP methods, overrides WithRetryMethods

func WithRetryMethods

func WithRetryMethods(methods ...string) Option

WithRetryMethods specifies the methods that can be retried

func WithStrategy

func WithStrategy(s strategy.Strategy) Option

WithStrategy defines the backoff strategy to be used

type OptionsData

type OptionsData struct {
	MaxRetry        int
	Methods         map[string]bool
	RetryAllMethods bool
	Strategy        strategy.Strategy
}

OptionsData stores all options used across retry

type Retriable

type Retriable interface {
	//ShouldRetry should return when the failure needs to be retried
	ShouldRetry(attempt int, req *http.Request, resp *http.Response, err error) bool
	//WaitDuration should return the duration to wait before making next call
	WaitDuration(attempt int, req *http.Request, resp *http.Response, err error) time.Duration
}

Retriable is the interface implemented by a retrier

func NewRetry

func NewRetry(options ...Option) Retriable

NewRetry creates a new retry strategy

Jump to

Keyboard shortcuts

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