Documentation ¶
Index ¶
- Variables
- type Bar
- type BarStatString
- type BarTemplate
- type HttpHandle
- func (httpHandle *HttpHandle) AddHook(hook ...HttpHook)
- func (httpHandle *HttpHandle) Close() error
- func (httpHandle *HttpHandle) Done() <-chan error
- func (httpHandle *HttpHandle) ReplaceHeader(d http.Header)
- func (httpHandle *HttpHandle) SentHook()
- func (httpHandle *HttpHandle) SetClient(d *http.Client)
- func (httpHandle *HttpHandle) SetDebug(d bool)
- func (httpHandle *HttpHandle) SetHeader(k, v string)
- func (httpHandle *HttpHandle) SetOutdir(outdir string)
- func (httpHandle *HttpHandle) SetOutname(outname string)
- func (httpHandle *HttpHandle) SetSendHookIntervalTime(d time.Duration)
- func (httpHandle *HttpHandle) SetURI(uri string)
- func (httpHandle *HttpHandle) Start(ctx context.Context) error
- func (httpHandle *HttpHandle) Stat() *protocol.HttpStat
- func (httpHandle *HttpHandle) Wait() error
- type HttpHandleSetting
- func WithHttpClient(d *http.Client) HttpHandleSetting
- func WithHttpHook(hook ...HttpHook) HttpHandleSetting
- func WithHttpOutdir(d string) HttpHandleSetting
- func WithHttpOutname(d string) HttpHandleSetting
- func WithHttpReplaceHeader(d http.Header) HttpHandleSetting
- func WithHttpSendHookIntervalTime(d time.Duration) HttpHandleSetting
- type HttpHook
- type Rain
- func (rain *Rain) NewHttpHandle(uri string) *HttpHandle
- func (rain *Rain) RunHttp(uri string, settings ...HttpHandleSetting) (*HttpHandle, error)
- func (rain *Rain) RunHttpContext(ctx context.Context, uri string, settings ...HttpHandleSetting) (*HttpHandle, error)
- func (c Rain) SetAllowOverwrite(d bool)
- func (c Rain) SetBreakpointResume(d bool)
- func (c Rain) SetConnectTimeout(d time.Duration)
- func (c Rain) SetCreateDir(d bool)
- func (c Rain) SetDiskCache(d int)
- func (c Rain) SetProxy(d func(*http.Request) (*url.URL, error))
- func (c Rain) SetRetryNumber(d int)
- func (c Rain) SetRetryTime(d time.Duration)
- func (c Rain) SetSpeedLimit(d int)
- func (c Rain) SetThreadCount(d int)
- func (c Rain) SetThreadSize(d int)
- func (c Rain) SetTimeout(d time.Duration)
Constants ¶
This section is empty.
Variables ¶
var ( HttpBarHook = HttpBar(DefaultBar) WithHttpBarHook = WithHttpHook(HttpBarHook) )
var Default = New()
Default 默认的下载器
var DefaultBar = &Bar{ Template: &BarTemplate{ Template: `{{.CompletedLength}} / {{.TotalLength}} {{.Saucer}} {{.Progress}}% {{.DownloadSpeed}}/s {{.EstimatedTime}} CN:{{.Connections}}`, NoSizeTemplate: `{{.CompletedLength}} {{.DownloadSpeed}}/s {{.ConsumingTime}}`, Saucer: "=", SaucerHead: ">", SaucerPadding: "-", BarStart: "[", BarEnd: "]", BarWidth: 80, }, FriendlyFormat: true, Hide: false, Stdout: os.Stdout, FinishHide: false, }
Functions ¶
This section is empty.
Types ¶
type Bar ¶
type Bar struct { // Template 进度条样式 Template *BarTemplate // FriendlyFormat 使用人类友好的单位 FriendlyFormat bool // FinishHide 完成后隐藏进度条,下载完成后清除掉进度条 FinishHide bool // Hide 是否隐藏进度条 Hide bool // Stdout 进度条输出, 默认为 os.Stdout Stdout io.Writer }
Bar 提供一个简单的进度条
type BarStatString ¶
type BarStatString struct { // TotalLength 文件总大小 TotalLength string // CompletedLength 已下载大小 CompletedLength string // DownloadSpeed 文件每秒下载速度 DownloadSpeed string // EstimatedTime 预计下载完成还需要的时间 EstimatedTime string // Progress 下载进度, 长度为 100 Progress string // Saucer 进度条 Saucer string // Connections 与服务器的连接数 Connections string }
BarStatString 注入到模版中的字符串结构 {{.CompletedLength}} / {{.TotalLength}} {{.Saucer}} {{.Progress}}% {{.DownloadSpeed}}/s {{.EstimatedTime}}
type BarTemplate ¶
type BarTemplate struct { // Template 模版 Template string // NoSizeTemplate 获取不到文件大小时的模板 NoSizeTemplate string // Saucer 进度字符, 默认为 = Saucer string // SaucerHead 进度条头, 使用场景 =====> , 其中的 > 就是进度条头, 默认为 > SaucerHead string // SaucerPadding 进度空白字符, 默认为 - SaucerPadding string // BarStart 进度前缀, 默认为 [ BarStart string // BarEnd 进度后缀, 默认为 ] BarEnd string // BarWidth 进度条宽度, 默认为 80 BarWidth int }
BarTemplate 进度条显示内容的参数
type HttpHandle ¶
type HttpHandle struct {
// contains filtered or unexported fields
}
HttpHandle HTTP 协议文件下载
func (*HttpHandle) AddHook ¶ added in v0.2.0
func (httpHandle *HttpHandle) AddHook(hook ...HttpHook)
AddHook 添加 Hook
func (*HttpHandle) ReplaceHeader ¶
func (httpHandle *HttpHandle) ReplaceHeader(d http.Header)
ReplaceHeader 替换掉 Header
func (*HttpHandle) SentHook ¶ added in v0.2.0
func (httpHandle *HttpHandle) SentHook()
SentHook 发送 hook 信息
func (*HttpHandle) SetClient ¶
func (httpHandle *HttpHandle) SetClient(d *http.Client)
SetClient 设置 http 客户端
func (*HttpHandle) SetHeader ¶
func (httpHandle *HttpHandle) SetHeader(k, v string)
SetHeader 设置 Header
func (*HttpHandle) SetOutdir ¶
func (httpHandle *HttpHandle) SetOutdir(outdir string)
SetOutdir 设置输出目录
func (*HttpHandle) SetOutname ¶
func (httpHandle *HttpHandle) SetOutname(outname string)
SetOutname 设置输出名称
func (*HttpHandle) SetSendHookIntervalTime ¶ added in v0.2.0
func (httpHandle *HttpHandle) SetSendHookIntervalTime(d time.Duration)
SetSendHookIntervalTime 设置发送 hook 间隔时间
type HttpHandleSetting ¶ added in v0.2.0
type HttpHandleSetting func(*HttpHandle)
HttpHandleSetting HTTP 下载的设置
func WithHttpClient ¶ added in v0.2.0
func WithHttpClient(d *http.Client) HttpHandleSetting
WithHttpClient 设置输出名称
func WithHttpHook ¶ added in v0.2.0
func WithHttpHook(hook ...HttpHook) HttpHandleSetting
WithHttpHook 添加 Hook
func WithHttpOutdir ¶ added in v0.2.0
func WithHttpOutdir(d string) HttpHandleSetting
WithHttpOutdir 设置输出目录
func WithHttpOutname ¶ added in v0.2.0
func WithHttpOutname(d string) HttpHandleSetting
WithHttpOutname 设置输出名称
func WithHttpReplaceHeader ¶ added in v0.2.0
func WithHttpReplaceHeader(d http.Header) HttpHandleSetting
WithHttpReplaceHeader 替换掉 Header
func WithHttpSendHookIntervalTime ¶ added in v0.2.0
func WithHttpSendHookIntervalTime(d time.Duration) HttpHandleSetting
WithHttpSendHookIntervalTime 设置发送 hook 间隔时间
type Rain ¶
type Rain struct {
// contains filtered or unexported fields
}
func (*Rain) NewHttpHandle ¶
func (rain *Rain) NewHttpHandle(uri string) *HttpHandle
NewHttpHandle 创建 http 协议下载器
func (*Rain) RunHttp ¶
func (rain *Rain) RunHttp(uri string, settings ...HttpHandleSetting) (*HttpHandle, error)
func (*Rain) RunHttpContext ¶
func (rain *Rain) RunHttpContext(ctx context.Context, uri string, settings ...HttpHandleSetting) (*HttpHandle, error)
RunHttpContext 阻塞运行一个默认的 http 下载器 ctx 上下文,可以创建上下文来控制运行的关闭 uri 资源地址,要下载的 http 文件地址
func (Rain) SetAllowOverwrite ¶
func (c Rain) SetAllowOverwrite(d bool)
SetAllowOverwrite 设置是否允许覆盖文件
func (Rain) SetBreakpointResume ¶
func (c Rain) SetBreakpointResume(d bool)
SetBreakpointResume 设置是否开启断点续传
func (Rain) SetConnectTimeout ¶
SetConnectTimeout HTTP 连接请求的超时时间,默认为 5 秒