-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (37 loc) · 884 Bytes
/
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
package main
import (
"flag"
"runtime"
"sync"
)
func main() {
maxWorkers := runtime.NumCPU()
var (
file,
username,
password string
)
flag.StringVar(&file, "file", "repos.json", "JSON file with repositories")
flag.StringVar(&username, "username", "", "username (case authentication is required)")
flag.StringVar(&password, "password", "", "password (case authentication is required)")
flag.Parse()
username, password = getCredentials(username, password)
projects := getRepos(file)
var wg sync.WaitGroup
wg.Add(len(projects))
projectChan := make(chan Repo, len(projects))
defer close(projectChan)
for _, v := range projects {
projectChan <- v
}
for i := 0; i < maxWorkers; i++ {
go func() {
for v := range projectChan {
downloadRepo(v, username, password)
print(v.Url, "downloaded to", v.Folder)
wg.Done()
}
}()
}
wg.Wait()
}