Documentation ¶
Index ¶
- type DownloadTask
- func (d *DownloadTask) AddHeader(key, value string) *DownloadTask
- func (d *DownloadTask) AddHostNameToHeader(host string) *DownloadTask
- func (d *DownloadTask) CalculateSpeed(elapse time.Duration) string
- func (d *DownloadTask) Cancel()
- func (d *DownloadTask) CleanTempFiles()
- func (d *DownloadTask) Download() (err error)
- func (d *DownloadTask) DownloadWithChannel() (ch chan error)
- func (d *DownloadTask) ForceHttp() *DownloadTask
- func (d *DownloadTask) ForceHttps() *DownloadTask
- func (d *DownloadTask) ForceMultiThread() *DownloadTask
- func (d *DownloadTask) GetFileSize() int64
- func (d *DownloadTask) GetHostName() string
- func (d *DownloadTask) GetWrittenBytes() int64
- func (d *DownloadTask) IgnoreCertificateVerify() *DownloadTask
- func (d *DownloadTask) ReplaceHostName(host string) *DownloadTask
- func (d *DownloadTask) SetFileName(fileName string) *DownloadTask
- func (d *DownloadTask) WithResolvedIp(ip string) *DownloadTask
- func (d *DownloadTask) WithResolvedIpOnHost(ip string) *DownloadTask
- type Downloader
- func (d *Downloader) NewDownloadTask(URL string) (*DownloadTask, error)
- func (d *Downloader) SetBreakPoint(isEnabled bool) *Downloader
- func (d *Downloader) SetDownloadRoutine(routine int) *Downloader
- func (d *Downloader) SetNoProxy() *Downloader
- func (d *Downloader) SetProxy(host string) *Downloader
- func (d *Downloader) SetSavePath(path string) *Downloader
- func (d *Downloader) SetTimeOut(timeout time.Duration) *Downloader
- func (d *Downloader) SetUserAgent(userAgent string) *Downloader
- type HttpProxy
- type ReaderF
- type WriterF
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DownloadTask ¶
type DownloadTask struct { Downloader *Downloader Scheme string Host string Path string Query string // contains filtered or unexported fields }
func (*DownloadTask) AddHeader ¶
func (d *DownloadTask) AddHeader(key, value string) *DownloadTask
AddHeader add a http header to the task
func (*DownloadTask) AddHostNameToHeader ¶
func (d *DownloadTask) AddHostNameToHeader(host string) *DownloadTask
AddHostNameToHeader add the host name to the header
func (*DownloadTask) CalculateSpeed ¶
func (d *DownloadTask) CalculateSpeed(elapse time.Duration) string
CalculateSpeed returns the download speed of the current task.
func (*DownloadTask) CleanTempFiles ¶
func (d *DownloadTask) CleanTempFiles()
CleanTempFiles delete the temp files of the task
func (*DownloadTask) Download ¶
func (d *DownloadTask) Download() (err error)
Download starts the download task
func (*DownloadTask) DownloadWithChannel ¶
func (d *DownloadTask) DownloadWithChannel() (ch chan error)
DownloadWithChannel returns a channel to receive the error
func (*DownloadTask) ForceHttp ¶
func (d *DownloadTask) ForceHttp() *DownloadTask
ForceHttp set the scheme to http
func (*DownloadTask) ForceHttps ¶
func (d *DownloadTask) ForceHttps() *DownloadTask
ForceHttps set the scheme to https
func (*DownloadTask) ForceMultiThread ¶
func (d *DownloadTask) ForceMultiThread() *DownloadTask
ForceMultiThread force to use multi-thread download without checking the Accept-Ranges header
func (*DownloadTask) GetFileSize ¶
func (d *DownloadTask) GetFileSize() int64
GetFileSize return the content length of the task
func (*DownloadTask) GetHostName ¶
func (d *DownloadTask) GetHostName() string
GetHostName return the real host name of the task
func (*DownloadTask) GetWrittenBytes ¶
func (d *DownloadTask) GetWrittenBytes() int64
GetWrittenBytes return the downloaded bytes number of the task
func (*DownloadTask) IgnoreCertificateVerify ¶
func (d *DownloadTask) IgnoreCertificateVerify() *DownloadTask
IgnoreCertificateVerify ignore the SSL certificate verification
func (*DownloadTask) ReplaceHostName ¶
func (d *DownloadTask) ReplaceHostName(host string) *DownloadTask
ReplaceHostName replace the host name in url
func (*DownloadTask) SetFileName ¶
func (d *DownloadTask) SetFileName(fileName string) *DownloadTask
SetFileName set the file name of the task
func (*DownloadTask) WithResolvedIp ¶
func (d *DownloadTask) WithResolvedIp(ip string) *DownloadTask
WithResolvedIp will force to make http request with the specific IP address like the "--resolve" option in curl.
For example:
d := downloader.NewDownloader() task, _ := d.NewDownloadTask("https://www.example.com/1.jpg") task.WithResolvedIp("114.5.1.4").Download()
This is similar to:
curl --resolve www.example.com:443:114.5.1.4 https://www.example.com/1.jpg
func (*DownloadTask) WithResolvedIpOnHost ¶
func (d *DownloadTask) WithResolvedIpOnHost(ip string) *DownloadTask
WithResolvedIpOnHost is similar to WithResolvedIp, but instead of replacing the dns record, it replaces the host name in url and add the original host name to the header.
For example:
d := downloader.NewDownloader() task, _ := d.NewDownloadTask("https://www.example.com/1.jpg") task.WithResolvedIp("114.5.1.4:23333").Download()
It is similar to:
curl -H "Host: www.example.com" https://114.5.1.4:23333/1.jpg
This can be used to download a file through your own hosted reverse proxy server.
Notice that enable this option will default ignore the SSL certificate verification.
type Downloader ¶
type Downloader struct { SavePath string HttpProxy HttpProxy TimeOut time.Duration UserAgent string DownloadRoutine int BreakPoint bool }
func (*Downloader) NewDownloadTask ¶
func (d *Downloader) NewDownloadTask(URL string) (*DownloadTask, error)
NewDownloadTask is to create a new download task belongs to the downloader
func (*Downloader) SetBreakPoint ¶
func (d *Downloader) SetBreakPoint(isEnabled bool) *Downloader
SetBreakPoint set the break point download
func (*Downloader) SetDownloadRoutine ¶
func (d *Downloader) SetDownloadRoutine(routine int) *Downloader
SetDownloadRoutine set the threads to download
func (*Downloader) SetNoProxy ¶
func (d *Downloader) SetNoProxy() *Downloader
SetNoProxy disable the proxy settings from environment
func (*Downloader) SetProxy ¶
func (d *Downloader) SetProxy(host string) *Downloader
SetProxy set the proxy settings
func (*Downloader) SetSavePath ¶
func (d *Downloader) SetSavePath(path string) *Downloader
SetSavePath set the path to save files
func (*Downloader) SetTimeOut ¶
func (d *Downloader) SetTimeOut(timeout time.Duration) *Downloader
SetTimeOut set the context timeout
func (*Downloader) SetUserAgent ¶
func (d *Downloader) SetUserAgent(userAgent string) *Downloader
SetUserAgent set the user agent