gex

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2022 License: MIT Imports: 14 Imported by: 2

README

gex

Goland http file download library with http range support.

GitHub license

Install
> go get github.com/gonejack/gex
Usage

single task

func TestSingle(t *testing.T) {
    task := gex.NewTask("https://wx2.sinaimg.cn/large/008h3uCply1gtumw52q7aj31nj27enk8.jpg")
    task.SetTimeout(time.Second * 10)
    err := task.Do(context.TODO())
    if err == nil {
        println(humanize.IBytes(uint64(task.Result().Transfer())))
        println(task.Result().Transfer())
    }
}

batch tasks

func TestMany(t *testing.T) {
    t1 := gex.NewTask("https://wx2.sinaimg.cn/large/008h3uCply1gtumw52q7aj31nj27enk8.jpg")
    t2 := gex.NewTask("https://wx1.sinaimg.cn/large/002MwiQagy1gwmv16ypycj60dcatwe8102.jpg")
    
    var bat gex.Batch
    
    bat.Add(t1, t2)
    bat.Run()
    
    t.Log(t1.Result())
    t.Log(t2.Result().Err)
    t.Log(t2.Result().Time())
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultHeader

func DefaultHeader() (h http.Header)

func NewBatch

func NewBatch(concurrent int) *batch

Types

type Request

type Request struct {
	Url      string
	Header   http.Header
	Output   string
	Timeout  time.Duration `json:"-"`
	Response *Response     `json:"-"`
}

func NewRequest

func NewRequest(dir string, requrl string) (r *Request)

func (*Request) Do

func (r *Request) Do(ctx context.Context) (err error)

func (*Request) DoWithClient

func (r *Request) DoWithClient(ctx context.Context, client *http.Client) (err error)

type Response

type Response struct {
	Request *Request
	Output  string
	Header  http.Header
	Start   time.Time `json:"-"`
	End     time.Time `json:"-"`
	Size    int64
}

func (*Response) Ext

func (r *Response) Ext() (ext string)

func (*Response) Mime

func (r *Response) Mime() string

func (*Response) ModTime

func (r *Response) ModTime() (t time.Time)

Jump to

Keyboard shortcuts

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