swhttp

package
v0.12.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultClient = http.Client{
	Timeout: time.Minute * 5,
}

Functions

func Download

func Download(ctx context.Context, url string) (*bytes.Buffer, error)

Download downloads the file at the provided URL using the default client. It returns the response in a bytes.Buffer.

func DownloadWithClient

func DownloadWithClient(ctx context.Context, client http.Client, url string) (*bytes.Buffer, error)

DownloadWithClient downloads the file at the provided URL using the provided client. It returns the response in a bytes.Buffer if successful.

func HandleResponse

func HandleResponse(res *http.Response, err error) error

HandleResponse is a utility function for standardizing failed responses. It checks the HTTP status code for a success response (200-299), and will attach the body of the response in the event of a non-200 response. This should be called immediately after an HTTP request, rather than checking immediately for the error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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