forked from greenboxal/dns-heaven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (36 loc) · 904 Bytes
/
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 (
"flag"
"os"
"os/signal"
"github.com/greenboxal/dns-heaven"
"github.com/greenboxal/dns-heaven/osx"
"github.com/sirupsen/logrus"
)
var config = &dnsheaven.Config{}
func init() {
flag.StringVar(&config.Address, "address", "127.0.0.1:53", "address to listen")
flag.IntVar(&config.Timeout, "timeout", 2000, "request timeout")
flag.IntVar(&config.Interval, "interval", 1000, "interval between requests")
}
func main() {
flag.Parse()
resolver, err := osx.New(config)
if err != nil {
logrus.WithError(err).Error("error starting server")
os.Exit(1)
}
server := dnsheaven.NewServer(config, resolver)
stopping := false
go func() {
err := server.Start()
if !stopping && err != nil {
logrus.WithError(err).Error("error starting server")
os.Exit(1)
}
}()
sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt)
_ = <-sig
server.Shutdown()
}