retryhttp

package module
v0.0.0-...-40df97a Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2023 License: MIT Imports: 12 Imported by: 0

README

Retry HTTP Wrapper

Installation

go get -u github.com/gowool/retryhttp

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultRetryPolicy

func DefaultRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error)

func ErrorPropagatedRetryPolicy

func ErrorPropagatedRetryPolicy(ctx context.Context, resp *http.Response, err error) (bool, error)

ErrorPropagatedRetryPolicy is the same as DefaultRetryPolicy, except it propagates errors back instead of returning nil. This allows you to inspect why it decided to retry or not.

func ManyRequests

func ManyRequests(r *http.Response, header string) (time.Duration, bool)

Types

type Backoff

type Backoff func(min, max time.Duration, attemptNum int, r *http.Response) time.Duration

func DefaultBackoff

func DefaultBackoff(header string) Backoff

type CheckRetry

type CheckRetry func(ctx context.Context, resp *http.Response, err error) (bool, error)

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
	CloseIdleConnections()
}

type Option

type Option func(client *RetryClient)

func WithBackoff

func WithBackoff(backoff Backoff) Option

func WithCheckRetry

func WithCheckRetry(checkRetry CheckRetry) Option

func WithInnerClient

func WithInnerClient(inner Client) Option

func WithLogger

func WithLogger(logger *slog.Logger) Option

func WithRetryMax

func WithRetryMax(m int) Option

func WithRetryWaitMax

func WithRetryWaitMax(m time.Duration) Option

func WithRetryWaitMin

func WithRetryWaitMin(m time.Duration) Option

type RLClient

type RLClient struct {
	// contains filtered or unexported fields
}

func NewRLClient

func NewRLClient(inner Client, limit rate.Limit, burst int) *RLClient

func (*RLClient) CloseIdleConnections

func (c *RLClient) CloseIdleConnections()

func (*RLClient) Do

func (c *RLClient) Do(req *http.Request) (*http.Response, error)

type RetryClient

type RetryClient struct {
	// contains filtered or unexported fields
}

func NewRetryClient

func NewRetryClient(options ...Option) *RetryClient

func (*RetryClient) CloseIdleConnections

func (c *RetryClient) CloseIdleConnections()

func (*RetryClient) Do

func (c *RetryClient) Do(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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