-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
46 lines (39 loc) · 985 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
package main
import (
"fmt"
"os"
"strconv"
"github.com/miekg/dns"
"go.uber.org/zap"
)
func buildLogger() (*zap.Logger, error) {
if debug, _ := strconv.ParseBool(os.Getenv("MAPDNS_DEBUG")); debug {
return zap.NewDevelopment()
} else {
return zap.NewProduction()
}
}
func main() {
logger, err := buildLogger()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed build logger: %v", err)
return
}
defer func() {
if err := logger.Sync(); err != nil {
fmt.Fprintf(os.Stderr, "Failed to sync logger: %v", err)
}
}()
cfg, err := ReadConfig("mapdns.json")
if err != nil {
logger.Error("Failed to read config", zap.Error(err))
return
}
logger.Debug("Read config", zap.Any("config", cfg))
srv := &dns.Server{Addr: ":53", Net: "udp"}
srv.Handler = &Handler{logger: logger, cfg: cfg}
logger.Info("Starting server", zap.String("addr", srv.Addr))
if err := srv.ListenAndServe(); err != nil {
logger.Error("Failed to set udp listener", zap.Error(err))
}
}