-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
68 lines (57 loc) · 1.42 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
package main
import (
"encoding/json"
"flag"
"os"
"os/signal"
"syscall"
"github.com/jinliming2/secure-dns/client"
"github.com/jinliming2/secure-dns/config"
"github.com/jinliming2/secure-dns/versions"
)
func main() {
var (
configFile = flag.String("config", "/etc/"+versions.PROGRAM+"/config.toml", "Config file")
version = flag.Bool("version", false, "Show version")
logLevel = flag.String("logLevel", "info", "Set log level (error, warn, info, verbose)")
verbose = flag.Bool("verbose", false, "Set log level to verbose")
)
flag.Parse()
if *version {
versions.PrintVersion()
return
}
if *verbose {
setLogLevel("verbose")
} else {
setLogLevel(*logLevel)
}
logger.Infof("Reading configuration file: %s", *configFile)
config, err := config.LoadConfig(*configFile)
if err != nil {
logger.Errorf("Error while handling configuration file: %s", err.Error())
os.Exit(1)
}
if loggerConfig.Level.Level() < 0 {
json, _ := json.MarshalIndent(*config, "", " ")
logger.Debugf("Configuration file: %s", json)
}
dnsClient, err := client.NewClient(logger, config)
if err != nil {
logger.Error(err)
os.Exit(1)
}
go func() {
err := dnsClient.ListenAndServe(config.Config.Listen)
if err != nil {
os.Exit(1)
} else {
os.Exit(0)
}
}()
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM, syscall.SIGKILL)
<-sig
logger.Info("Exiting")
dnsClient.Shutdown()
}