sacrebleu-dns/main.go
2020-12-13 14:40:14 -04:00

43 lines
946 B
Go

package main
import (
"database/sql"
"strconv"
"github.com/miekg/dns"
"github.com/outout14/sacrebleu-dns/core"
"github.com/outout14/sacrebleu-dns/utils"
"github.com/sirupsen/logrus"
"gopkg.in/ini.v1"
)
//Global vars
var conf *utils.Conf
var DB *sql.DB
//Main loop
func main() {
//Load Configuration
conf = new(utils.Conf)
err := ini.MapTo(conf, "./config.ini")
utils.CheckErr(err)
utils.InitLogger(conf)
// attach request handler func
dns.HandleFunc(".", core.HandleDnsRequest)
//Init redis database
utils.RedisDatabase(conf)
//Init sql database
utils.SqlDatabase(conf)
// start server
server := &dns.Server{Addr: conf.App.Ip + strconv.Itoa(conf.App.Port), Net: "udp"} //define the server
logrus.WithFields(logrus.Fields{"ip": conf.App.Ip, "port": conf.App.Port}).Infof("SERVER : Started")
err = server.ListenAndServe() //start it
utils.CheckErr(err)
defer server.Shutdown() //shut down on application closing
}