-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (52 loc) · 1.09 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
58
59
60
package main
import (
"flag"
"fmt"
"log"
"math/rand"
"os"
"sync"
"time"
)
var (
path = flag.String("config", "", "Path to config in form of file or URL, required")
debug = flag.Bool("debug", false, "Print debug info, optional")
)
func main() {
flag.Parse()
log.SetFlags(log.Lshortfile | log.LstdFlags)
rand.Seed(time.Now().UnixNano())
if *path == "" {
flag.PrintDefaults()
os.Exit(1)
}
conf, err := getConfig(*path)
if err != nil {
log.Fatal("Can't process config: ", err)
}
errors := make(chan *RequestError, conf.getSize())
execute(conf, errors)
checkErrors(errors)
fmt.Println("Done!")
}
func execute(conf *Config, errors chan<- *RequestError) {
var wg sync.WaitGroup
if len(conf.Cloudflare) > 0 {
wg.Add(len(conf.Cloudflare))
invalidateCloudflare(conf.Cloudflare, &wg, errors)
}
if len(conf.Cloudfront) > 0 {
wg.Add(len(conf.Cloudfront))
invalidateCloudfront(conf.Cloudfront, &wg, errors)
}
wg.Wait()
close(errors)
}
func checkErrors(errors <-chan *RequestError) {
if len(errors) > 0 {
for v := range errors {
fmt.Println(v.toString())
}
os.Exit(1)
}
}