get

package module
v1.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2021 License: MIT Imports: 8 Imported by: 4

README

get

Basic download library in golang

Install
> go get github.com/gonejack/get
Usage
func main() {
	err := get.Download("https://www.qq.com", "test.html", time.Second*3)
	if err != nil {
		log.Fatal(err)
	}

	errors := get.Batch(map[string]string{"https://www.qq.com": "test.html"}, 3, time.Second*3)
	for _, e := range errors {
		log.Print(e)
	}

	refs, errs := get.BatchInOrder([]string{"https://www.qq.com"}, []string{"test.html"}, 3, time.Second*3)
	for i := range refs {
		log.Printf("%s: %s", refs[i], errs[i])
	}
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Download

func Download(dl *DownloadTask, timeout time.Duration) (err error)

func DownloadWithContext

func DownloadWithContext(ctx context.Context, dl *DownloadTask) (err error)

Types

type DownloadTask added in v1.0.7

type DownloadTask struct {
	Link string
	Path string
	Err  error
}

func NewDownloadTask added in v1.0.8

func NewDownloadTask(link, path string) *DownloadTask

type DownloadTasks added in v1.0.8

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

func Batch

func Batch(tasks *DownloadTasks, concurrent int, eachTimeout time.Duration) *DownloadTasks

func NewDownloadTasks added in v1.0.8

func NewDownloadTasks() *DownloadTasks

func (*DownloadTasks) Add added in v1.0.8

func (d *DownloadTasks) Add(link, path string)

func (*DownloadTasks) ForEach added in v1.0.8

func (d *DownloadTasks) ForEach(f func(t *DownloadTask))

type Get added in v1.0.7

type Get struct {
	OnEachStart func(t *DownloadTask)
	OnEachStop  func(t *DownloadTask)
	OnEachSkip  func(t *DownloadTask)
	Header      http.Header
	Client      http.Client
}

func Default added in v1.0.7

func Default() (g Get)

func (*Get) Batch added in v1.0.7

func (g *Get) Batch(tasks *DownloadTasks, concurrent int, eachTimeout time.Duration) *DownloadTasks

func (*Get) Download added in v1.0.7

func (g *Get) Download(task *DownloadTask, timeout time.Duration) (err error)

func (*Get) DownloadWithContext added in v1.0.7

func (g *Get) DownloadWithContext(ctx context.Context, task *DownloadTask) (err error)

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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