client

package
v0.6.24 Latest Latest
Warning

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

Go to latest
Published: May 31, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientConfiguration    = errors.New("client misconfigured")
	ErrHTTPResponseStatusCode = errors.New("received error status code")
	ErrInvalidURL             = errors.New("invalid URL")
	ErrMissingSize            = errors.New("missing progress size")
	ErrMissingURL             = errors.New("missing URL")
	ErrRequestFailed          = errors.New("request failed")
	ErrUnexpectedRedirect     = errors.New("unexpected redirect")
)

Functions

func ParseURL

func ParseURL(urlBaseRaw string, urlPartsRaw ...string) (*url.URL, error)

Returns a parsed URL or fails if it's invalid.

func WithProgress

func WithProgress(ctx context.Context, p *progress.Progress) context.Context

WithProgress creates a sub-context with an associated progress reporter. The result can be passed to file download functions in this package to get updates on download progress.

Types

type Client

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

A struct implementing an HTTP client with simple methods for file downloads.

func New

func New() *Client

Creates a new 'Client' with default settings for mirrors.

func NewWithRedirectDomains

func NewWithRedirectDomains(domains ...string) *Client

Creates a new 'Client' with the provided domains allowed for redirects. If none are provided, then no redirects are permitted.

func (*Client) Download

func (c *Client) Download(ctx context.Context, u *url.URL, w ...io.Writer) error

Downloads the provided asset, copying the response to all of the provided 'io.Writer' writers. Reports progress to a 'progress.Progress' set on the provided context.

func (*Client) DownloadTo

func (c *Client) DownloadTo(ctx context.Context, u *url.URL, out string) error

Downloads the provided asset to a specified file 'out'. Reports progress to a 'progress.Progress' set on the provided context.

func (*Client) Exists

func (c *Client) Exists(ctx context.Context, urlBaseRaw string, urlPartsRaw ...string) (bool, error)

Issues a 'HEAD' request to test whether or not the URL is reachable.

func (*Client) RestyClient

func (c *Client) RestyClient() *resty.Client

RestyClient returns the underlying 'resty.Client'. Exposing this allows for tests in other packages to stub responses.

TODO: Find an alternative way of allowing other packages to stub responses without exposing the use of 'resty'.

Jump to

Keyboard shortcuts

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