-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (36 loc) · 1 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
package main
import (
"os"
"sync"
dhcp "github.com/krolaw/dhcp4"
log "github.com/sirupsen/logrus"
)
func main() {
// WaitGroup for multiple servers on separate co-routines
wg := &sync.WaitGroup{}
// Log as JSON instead of the default ASCII formatter.
log.SetFormatter(&log.JSONFormatter{})
// Output to stdout instead of the default stderr
// Can be any io.Writer, see below for File example
log.SetOutput(os.Stdout)
// Only log the warning severity or above.
log.SetLevel(log.DebugLevel)
log.WithFields(log.Fields{})
rl := NewLogger(log.New().Writer())
dhcpHandler := newDHCPServer()
dnsHandler := newDefaultDNSServerHandler()
go func() {
wg.Add(1)
rl.Fatal(dhcp.ListenAndServe(dhcpHandler))
wg.Done()
}()
rl.Infof("DHCP on %s:%d", DHCP_SERVER_ADDR, DHCP_SERVER_PORT)
go func() {
wg.Add(1)
rl.Fatal(dnsHandler.RouteDNS())
wg.Done()
}()
rl.Infof("DNS on %s:%d", DNS_SERVER_ADDR, DNS_SERVER_PORT)
rl.Infof("xserver is running and serving: %s, %s", "DHCP", "DNS")
wg.Wait()
}