retryable

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package retryable is a legacy package, functionality has been moved to reghttp

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrAllRequestsFailed when there are no mirrors left to try
	ErrAllRequestsFailed = errors.New("all requests failed")
	// ErrBackoffLimit maximum backoff attempts reached
	ErrBackoffLimit = errors.New("backoff limit reached")
	// ErrCanceled if the context was canceled
	ErrCanceled = errors.New("context was canceled")
	// ErrDigestMismatch if the expected digest wasn't received
	ErrDigestMismatch = errors.New("digest mismatch")
	// ErrNotFound isn't there, search for your value elsewhere
	ErrNotFound = errors.New("not found")
	// ErrNotImplemented returned when method has not been implemented yet
	ErrNotImplemented = errors.New("not implemented")
	// ErrRetryNeeded indicates a request needs to be retried
	ErrRetryNeeded = errors.New("retry needed")
	// ErrUnauthorized request was not authorized
	ErrUnauthorized = errors.New("unauthorized")
)

Functions

This section is empty.

Types

type Auth

type Auth interface {
	AddScope(host, scope string) error
	HandleResponse(*http.Response) error
	UpdateRequest(*http.Request) error
}

Auth is used to process Www-Authenticate header and update request with Authorization header

type Opts

type Opts func(*retryable)

Opts injects options into NewRetryable

func WithAuth

func WithAuth(auth Auth) Opts

WithAuth adds authentication to retryable methods

func WithCertFiles

func WithCertFiles(files []string) Opts

WithCertFiles adds certificates by filename

func WithCerts

func WithCerts(certs [][]byte) Opts

WithCerts adds certificates

func WithDelay

func WithDelay(delayInit time.Duration, delayMax time.Duration) Opts

WithDelay initial time to wait between retries (increased with exponential backoff)

func WithHTTPClient

func WithHTTPClient(h *http.Client) Opts

WithHTTPClient uses a specific http client with retryable requests

func WithLimit

func WithLimit(l int) Opts

WithLimit restricts the number of retries (defaults to 5)

func WithLog

func WithLog(log *logrus.Logger) Opts

WithLog injects a logrus Logger configuration

func WithTransport

func WithTransport(t *http.Transport) Opts

WithTransport uses a specific http transport with retryable requests

func WithUserAgent

func WithUserAgent(ua string) Opts

WithUserAgent sets a user agent header

type OptsReq

type OptsReq func(*request)

OptsReq injects options into NewRequest

func WithBodyBytes

func WithBodyBytes(body []byte) OptsReq

WithBodyBytes converts a bytes slice into a body func and content length

func WithBodyFunc

func WithBodyFunc(getbody func() (io.ReadCloser, error)) OptsReq

WithBodyFunc includes body content in a request

func WithChunking

func WithChunking() OptsReq

WithChunking allows content to be divided into multiple smaller chunks

func WithContentLen

func WithContentLen(l int64) OptsReq

WithContentLen sets the content length

func WithDigest

func WithDigest(d digest.Digest) OptsReq

WithDigest verifies the returned content digest matches. Note that the digest is only calculated upon EOF from the downloaded content, so the reader may receive an error rather than EOF from a digest mismatch. The content itself must still be read.

func WithHeader

func WithHeader(key string, values []string) OptsReq

WithHeader sets a header

func WithHeaders

func WithHeaders(headers http.Header) OptsReq

WithHeaders includes a header object

func WithProgressCB

func WithProgressCB(cb func(int64, error)) OptsReq

WithProgressCB calls the CB function as data is received

func WithScope

func WithScope(repo string, push bool) OptsReq

type Response

type Response interface {
	io.ReadCloser
	HTTPResponse() *http.Response
	HTTPResponses() ([]*http.Response, error)
}

Response is used to handle the result of a request

type Retryable

type Retryable interface {
	DoRequest(ctx context.Context, method string, u []url.URL, opts ...OptsReq) (Response, error)
	BackoffClear()
	BackoffUntil() time.Time
}

Retryable is used to create requests with built in retry capabilities

func NewRetryable

func NewRetryable(opts ...Opts) Retryable

NewRetryable returns a retryable interface

Jump to

Keyboard shortcuts

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