get

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2021 License: MIT Imports: 12 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 Batch

func Batch(downloads map[string]string, concurrent int, eachTimeout time.Duration) (errors map[string]error)

func BatchInOrder

func BatchInOrder(refs []string, paths []string, concurrent int, eachTimeout time.Duration) (errRefs []string, errors []error)

func Download

func Download(ref string, path string, timeout time.Duration) (err error)

func DownloadWithContext

func DownloadWithContext(ctx context.Context, ref string, path string) (err error)

Types

type Getter

type Getter struct {
	BeforeDL func(ref string, path string)
	AfterDL  func(ref string, path string, err error)

	Header  map[string]string
	Client  http.Client
	Verbose bool
}

func DefaultGetter

func DefaultGetter() Getter

func (*Getter) Batch

func (g *Getter) Batch(downloads map[string]string, concurrent int, eachTimeout time.Duration) (errors map[string]error)

func (*Getter) BatchInOrder

func (g *Getter) BatchInOrder(refs []string, paths []string, concurrent int, eachTimeout time.Duration) (errRefs []string, errors []error)

func (*Getter) Download

func (g *Getter) Download(ref string, path string, timeout time.Duration) (err error)

func (*Getter) DownloadWithContext

func (g *Getter) DownloadWithContext(ctx context.Context, ref string, path string) (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