-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (48 loc) · 1.18 KB
/
main.go
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
50
51
52
53
54
55
56
57
package main
import (
"flag"
"github.com/sado0823/downloader/internal"
"github.com/sado0823/downloader/internal/core"
"github.com/sado0823/downloader/internal/tool"
"log"
"runtime"
)
var (
url = flag.String("f", "https://download.jetbrains.com/go/goland-2020.2.2.dmg", "the download url")
count = flag.Int("c", runtime.NumCPU(), "parallel count, default is cpu num")
)
func main() {
flag.Parse()
//if *url == "" {
// //log.Fatalf("please enter your url")
//}
//folder, err := tool.DownloaderFolder(*url)
//if err != nil {
// log.Fatalf("error occured: %v", err)
//}
//if tool.FolderExist(folder) {
// fmt.Printf("Task already exist, remove it first \n")
// folder, err = tool.DownloaderFolder(*url)
// if err != nil {
// log.Fatalf("error occured: %v", err)
// }
// if err := os.RemoveAll(folder); err != nil {
// log.Fatalf("error occured: %v", err)
// }
//}
// resume
task := ""
if !tool.InvalidURL(*url) {
task = tool.DownloaderName(*url)
} else {
task = *url
}
state, err := core.Resume(task)
if err != nil {
log.Fatalf("error occured: %v", err)
}
err = internal.Do(*url, state, int64(*count))
if err != nil {
log.Fatalf("error occured: %v", err)
}
}