-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
53 lines (48 loc) · 1.25 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
package main
import (
"gopkg.in/yaml.v2"
"helm-chart-mirror/chart"
"helm-chart-mirror/fetch"
"io/ioutil"
"log"
"os"
"sync"
)
const (
OFFICAL_URL = "https://kubernetes-charts.storage.googleapis.com/index.yaml"
MAXFILE = 40
)
func main() {
var wg sync.WaitGroup
maxChan := make(chan bool, MAXFILE)
I := chart.Index{}
if err := yaml.Unmarshal(fetch.FetchIndexYaml(OFFICAL_URL), &I); err != nil {
log.Fatalf("Unmarshal struct %s Failed, Error is %s\n", I, err)
}
for _, charts := range I.Entries {
for _, chart := range charts {
wg.Add(1)
maxChan <- true
go chart.Download(&wg, maxChan)
}
}
wg.Wait()
I.SetGenerated()
d, err := yaml.Marshal(&I)
if err != nil {
log.Fatalf("Marshal struct %s Failed, Error is %s\n", I, err)
}
if err := ioutil.WriteFile("./docs/index.yaml", d, os.ModePerm); err != nil {
log.Fatalf("Write Index.yaml Failed, Error is %s\n", err)
}
}
//func GetOpenFiles() syscall.Rlimit {
// var rlimit syscall.Rlimit
// err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &rlimit)
// if err != nil {
// log.Fatalf("Get limit Error: %s\n", err)
// }
// log.Printf("Current Open Files Count is: %d\n", rlimit.Cur)
// log.Println("If you want to speed up download, Increase number by using `ulimit -n` command")
// return rlimit
//}