reghttp

package
v0.4.7 Latest Latest
Warning

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

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

Documentation

Overview

Package reghttp is used for HTTP requests to a registry

Index

Constants

View Source
const (
	DefaultRetryLimit = 3
)

Variables

This section is empty.

Functions

func HTTPError

func HTTPError(statusCode int) error

HTTPError returns an error based on the status code

Types

type Client

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

Client is an HTTP client wrapper It handles features like authentication, retries, backoff delays, TLS settings

func NewClient

func NewClient(opts ...Opts) *Client

NewClient returns a client for handling requests

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *Req) (Resp, error)

Do runs a request, returning the response result

type Opts

type Opts func(*Client)

Opts is used to configure client options

func WithCertDirs

func WithCertDirs(dirs []string) Opts

WithCertDirs adds directories to check for host specific certs

func WithCertFiles

func WithCertFiles(files []string) Opts

WithCertFiles adds certificates by filename

func WithCerts

func WithCerts(certs [][]byte) Opts

WithCerts adds certificates

func WithConfigHosts

func WithConfigHosts(ch []*config.Host) Opts

WithConfigHosts adds a list of config.Host entries to use for connection settings

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(hc *http.Client) Opts

WithHTTPClient uses a specific http client with retryable requests

func WithLog

func WithLog(log *logrus.Logger) Opts

WithLog injects a logrus Logger configuration

func WithRetryLimit

func WithRetryLimit(rl int) Opts

WithRetryLimit restricts the number of retries (defaults to 5)

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 Req

type Req struct {
	Host      string
	NoMirrors bool
	APIs      map[string]ReqAPI // allow different types of registries (registry/2.0, OCI, default to empty string)
}

Req is a request to send to a registry

type ReqAPI

type ReqAPI struct {
	Method     string
	DirectURL  *url.URL
	NoPrefix   bool
	Repository string
	Path       string
	Query      url.Values
	BodyLen    int64
	BodyBytes  []byte
	BodyFunc   func() (io.ReadCloser, error)
	Headers    http.Header
	Digest     digest.Digest
	IgnoreErr  bool
}

ReqAPI handles API specific settings in a request

type Resp

type Resp interface {
	io.ReadSeekCloser
	HTTPResponse() *http.Response
}

Resp is used to handle the result of a request

Jump to

Keyboard shortcuts

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