-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
80 lines (63 loc) · 1.87 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"flag"
"github.com/BenB196/crashplan-ffs-puller/config"
"github.com/BenB196/crashplan-ffs-puller/ffsEvent"
"github.com/BenB196/crashplan-ffs-puller/ip-api-local"
"github.com/prometheus/client_golang/prometheus/promhttp"
"log"
"net/http"
"strconv"
"sync"
"time"
)
func main() {
//Get Config location and get config struct
var configLocation string
flag.StringVar(&configLocation,"config","","Configuation File Location. REQUIRED") //TODO improve usage description
//Parse Flags
flag.Parse()
//Panic and die if configLocation not set
if configLocation == "" {
panic("config flag missing, required.")
}
//Get config struct
configuration, err := config.ReadConfig(configLocation)
if err != nil {
log.Println("Error parsing config file.")
panic(err)
}
//Print Auth and FFS URIs for debugging
log.Println(configuration.AuthURI)
log.Println(configuration.FFSURI)
if configuration.IPAPI.Enabled && configuration.IPAPI.LocalCache.Enabled &&
configuration.IPAPI.LocalCache.Persist {
//read ip-api proxy if enabled
ip_api_local.ReadCache(&configuration.IPAPI.LocalCache.WriteLocation)
//write ip-api proxy if enabled
writeIpApiTimeTicker := time.NewTicker(*configuration.IPAPI.LocalCache.WriteIntervalDuration)
go func() {
for {
select {
case <-writeIpApiTimeTicker.C:
ip_api_local.WriteCache(&configuration.IPAPI.LocalCache.WriteLocation)
}
}
}()
}
//Spawn goroutines for each ffs query provided
var wg sync.WaitGroup
wg.Add(len(configuration.FFSQueries))
go func() {
for _, query := range configuration.FFSQueries {
go ffsEvent.FFSQuery(*configuration, query)
wg.Done()
}
}()
if configuration.Prometheus.Enabled {
//startup prometheus metrics port
http.Handle("/metrics",promhttp.Handler())
log.Fatal(http.ListenAndServe(":" + strconv.Itoa(configuration.Prometheus.Port), nil))
}
wg.Wait()
}