net

package
v0.0.44 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2021 License: MIT Imports: 15 Imported by: 4

Documentation

Index

Constants

View Source
const (
	// ContentType is for the http header of content type
	ContentType = "Content-Type"
	// ApplicationForm is for the form submit
	ApplicationForm = "application/x-www-form-urlencoded"
)

Variables

This section is empty.

Functions

func DetectSize

func DetectSize(targetURL, output string, showProgress bool) (total int64, rangeSupport bool, err error)

DetectSize returns the size of target resource

func DownloadFileWithMultipleThread

func DownloadFileWithMultipleThread(targetURL, targetFilePath string, thread int, showProgress bool) (err error)

DownloadFileWithMultipleThread downloads the files with multiple threads

func DownloadFileWithMultipleThreadKeepParts

func DownloadFileWithMultipleThreadKeepParts(targetURL, targetFilePath string, thread int, keepParts, showProgress bool) (err error)

DownloadFileWithMultipleThreadKeepParts downloads the files with multiple threads

func GetExternalIP

func GetExternalIP() (string, error)

GetExternalIP returns an external ip of current machine

func SetProxy

func SetProxy(proxy, proxyAuth string, tr *http.Transport) (err error)

SetProxy set the proxy for a http

Types

type ContinueDownloader added in v0.0.32

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

ContinueDownloader is a downloader which support continuously download

func (*ContinueDownloader) DownloadWithContinue added in v0.0.32

func (c *ContinueDownloader) DownloadWithContinue(targetURL, output string, index, continueAt, end int64, showProgress bool) (err error)

DownloadWithContinue downloads the files continuously

type DownloadError

type DownloadError struct {
	StatusCode int
	Message    string
}

DownloadError represents the error of HTTP download

func (*DownloadError) Error

func (e *DownloadError) Error() string

Error print the error message

type HTTPDownloader

type HTTPDownloader struct {
	TargetFilePath     string
	URL                string
	ShowProgress       bool
	InsecureSkipVerify bool

	UserName string
	Password string

	Proxy     string
	ProxyAuth string

	Header map[string]string

	// PreStart returns false will don't continue
	PreStart func(*http.Response) bool

	Thread      int
	Title       string
	Timeout     int
	MaxAttempts int

	Debug        bool
	RoundTripper http.RoundTripper
	// contains filtered or unexported fields
}

HTTPDownloader is the downloader for http request

func (*HTTPDownloader) DownloadFile

func (h *HTTPDownloader) DownloadFile() error

DownloadFile download a file with the progress

type ProgressIndicator

type ProgressIndicator struct {
	Writer io.Writer
	Reader io.Reader
	Title  string

	// bytes.Buffer
	Total float64
	// contains filtered or unexported fields
}

ProgressIndicator hold the progress of io operation

func (ProgressIndicator) Close added in v0.0.32

func (i ProgressIndicator) Close()

Close shutdowns the ui process

func (*ProgressIndicator) Init

func (i *ProgressIndicator) Init()

Init set the default value for progress indicator

func (*ProgressIndicator) Read

func (i *ProgressIndicator) Read(p []byte) (n int, err error)

Read reads the progress

func (*ProgressIndicator) Write

func (i *ProgressIndicator) Write(p []byte) (n int, err error)

Write writes the progress

type RetryClient

type RetryClient struct {
	http.Client
	MaxAttempts int
	// contains filtered or unexported fields
}

RetryClient is the wrap of http.Client

func (*RetryClient) Do

func (c *RetryClient) Do(req *http.Request) (rsp *http.Response, err error)

Do is the wrap of http.Client.Do

Jump to

Keyboard shortcuts

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