forked from Razoralpha/name-dyndns
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
60 lines (49 loc) · 1.41 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"
"github.com/razoralpha/name-dyndns/api"
"github.com/razoralpha/name-dyndns/dyndns"
"github.com/razoralpha/name-dyndns/log"
"os"
)
func filterConfigs(configs []api.Config, dev bool) []api.Config {
for i := 0; i < len(configs); i++ {
if configs[i].Dev != dev {
configs = append(configs[:i], configs[i+1:]...)
}
}
return configs
}
func main() {
configPath := flag.String("config", "./config.json", "Specify the configuration file")
daemon := flag.Bool("daemon", false, "Operate in daemon mode.")
dev := flag.Bool("dev", false, "Use development configurations instead.")
logFile := flag.String("log", "", "Specify a logfile. If no file is provided, uses stdout.")
flag.Parse()
var file *os.File
defer file.Close()
if *logFile == "" {
file = os.Stdout
} else {
var err error
file, err = os.OpenFile(*logFile, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
if err != nil {
fmt.Println("Could not open log for reading")
os.Exit(1)
}
}
log.Init(file)
configs, err := api.LoadConfigs(*configPath)
if err != nil {
log.Logger.Fatalln("Error loading config:", err)
}
for _, config := range configs {
if config.Domain == "" || len(config.Hostnames) == 0 {
log.Logger.Fatalf("Empty configuration detected. Exiting.")
}
}
configs = filterConfigs(configs, *dev)
log.Logger.Printf("Successfully loaded %d configs\n", len(configs))
dyndns.Run(configs, *daemon)
}