get

package module
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: MIT Imports: 9 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 NewDownload added in v1.0.7

func NewDownload(ref, path string) *DownloadTask

type Downloads added in v1.0.7

type Downloads struct {
	List []*DownloadTask
}

func Batch

func Batch(jobs *Downloads, concurrent int, eachTimeout time.Duration) *Downloads

func NewDownloads added in v1.0.7

func NewDownloads() *Downloads

func (*Downloads) Add added in v1.0.7

func (d *Downloads) Add(ref, path string)

type Get added in v1.0.7

type Get struct {
	OnEachStart func(t *DownloadTask)
	OnEachStop  func(t *DownloadTask)
	Header      map[string]string
	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(downloads *Downloads, concurrent int, eachTimeout time.Duration) *Downloads

func (*Get) Download added in v1.0.7

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

func (*Get) DownloadWithContext added in v1.0.7

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

Directories

Path Synopsis
cmd
example command

Jump to

Keyboard shortcuts

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