common

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2022 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const HTTPTimeout time.Duration = 20 * time.Second

Default HTTP timeout value to be set

View Source
const UserAgent = "Mozilla/5.0 (X11; Linux x86_64; rv:90.0) Gecko/20100101 Firefox/90.0"

User agent to be used in all request

Variables

This section is empty.

Functions

func CheckStatus

func CheckStatus(resp *http.Response) error

func IntLength

func IntLength(n int) int

IntLength deduces the number of digits of an int

Types

type DownloadReq

type DownloadReq struct {
	Source string
	Dest   string
	Client *http.Client
	Fs     afero.Fs
	// contains filtered or unexported fields
}

DownloadReq represent a request for downloading Source is the source URL. While Dest is the destination in disk

Use NewDownloadReq to create this struct

func NewDownloadReq added in v1.1.0

func NewDownloadReq(source string, dest string, client *http.Client, fs afero.Fs, log logrus.FieldLogger) *DownloadReq

Create a new download request. Note that creating the request will not start downloading. [fs] and log are optional.

func (*DownloadReq) DestExist

func (meta *DownloadReq) DestExist() bool

DestExist checks if the file destination already has a file If true, the destination has a file. Exec should refuse to run

func (*DownloadReq) Exec

func (meta *DownloadReq) Exec(ctx context.Context) error

Execute the download plan. Download the url to filesystem. If download failed, this will try to delete the created file.

If the file already exist, download will be skipped.

type WithHeaderTransport

type WithHeaderTransport struct {
	http.Header
	// contains filtered or unexported fields
}

http.Transport with default header override

If `rt` field is nil, `http.DefaultTransport` will be used. Ref: https://stackoverflow.com/a/51326483/13226397

func NewWithHeaderTransport

func NewWithHeaderTransport(rt http.RoundTripper) WithHeaderTransport

func (WithHeaderTransport) RoundTrip

func (h WithHeaderTransport) RoundTrip(req *http.Request) (*http.Response, error)

Jump to

Keyboard shortcuts

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