~mendelmaleh/download

ref: d367236e0766f5511a5845f6fd923c6742c0c8e3 download/download.go -rw-r--r-- 941 bytes
d367236eMendel E Initial commit 1 year, 1 month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package download

import (
	"net/http"
	"sync"
)

// A type that satisfies download.Interface can be downloaded with download.Tar etc.
type Interface interface {
	URLs(sep string) []File
}

// File to download. URL is where to get the data, path is where to store it.
type File struct {
	Path, URL string
}

// DL is the downloader.
type DL struct {
	Client *http.Client
	Write  sync.Mutex
}

// Options for the downloader.
type Options struct {
	// Separator to use between files, eg you can use "_" for a flat
	// file structure, or leave the default "/" to have dirs.
	Separator string

	// Max attempts trying to download a file
	MaxAttempts int

	// Concurrent mode
	Concurrent bool
	// Max number of gorountines to spawn
	MaxGoroutines int
}

// Default Options
var DefaultOptions = &Options{
	Separator:     "/",
	MaxAttempts:   3,
	MaxGoroutines: 64,
}

// New DL instance.
func New() *DL {
	return &DL{Client: http.DefaultClient}
}