-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (43 loc) · 1.16 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
package main
import (
"Geo-DNS/healthchecks"
"Geo-DNS/server"
"Geo-DNS/stores"
"Geo-DNS/structs"
"Geo-DNS/util"
"fmt"
"os"
"github.com/ip2location/ip2location-go/v9"
"github.com/miekg/dns"
)
func main() {
go healthchecks.StartHealthChecks()
stores.Config = util.LoadConfig()
for popIp, popName := range stores.Config.Pops {
stores.AvailablePops = append(stores.AvailablePops, structs.Pop{
Ip: popIp,
Hostname: popName,
})
}
p, _ := os.Getwd()
loaded, e := ip2location.OpenDB(fmt.Sprintf("%v/%v", p, "IP2LOCATION-LITE-DB5.BIN"))
if e != nil {
fmt.Println("Could not load IP DB")
}
stores.Db = loaded
// Define DNS server configuration
addr := ":53" // Listen on port 53, the default DNS port
udpServer := &dns.Server{Addr: addr, Net: "udp"}
// Set up the DNS handler function
dns.HandleFunc(".", server.HandleDNSRequest)
// Start the DNS server
go func() {
if err := udpServer.ListenAndServe(); err != nil {
fmt.Printf("Failed to set up DNS server: %v\n", err)
os.Exit(1)
}
}()
fmt.Printf("DNS server listening on %s...\n", addr)
// Wait for an interrupt signal (e.g., Ctrl+C) to gracefully shut down the server
select {}
}