-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 1.08 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
package main
import (
"log"
"os"
"strings"
"time"
"go-getpi/config"
"go-getpi/helpers"
)
const version = "v0.0.1"
func main() {
log.Printf("running app version: %v", version)
helpers.InitLogger()
if len(os.Args) < 2 {
log.Fatalf("Usage: %s --config=config.json", os.Args[0])
}
configArg := os.Args[1]
if !strings.HasPrefix(configArg, "--config=") {
log.Fatalf("Usage: %s --config=config.json", os.Args[0])
}
cfgFile := strings.TrimPrefix(configArg, "--config=")
cfg, err := config.LoadConfig(cfgFile)
if err != nil {
log.Fatalf("Error loading config: %v", err)
}
if cfg.RunOnce {
err := helpers.SyncPihole(cfg, cfg.UpdateGravity, cfg.IntervalMinutes, cfg.SecondaryHostsAsStringSlice(), cfg.PrimaryHost.SslSecure)
if err != nil {
log.Fatalf("Error during sync: %v", err)
}
} else {
for {
err := helpers.SyncPihole(cfg, cfg.UpdateGravity, cfg.IntervalMinutes, cfg.SecondaryHostsAsStringSlice(), cfg.PrimaryHost.SslSecure)
if err != nil {
log.Printf("Error during sync: %v", err)
}
time.Sleep(time.Duration(cfg.IntervalMinutes) * time.Minute)
}
}
}