Listen in TCP & UDP.
This commit is contained in:
parent
8e5bf6ebdb
commit
dcd5da2cfb
1 changed files with 24 additions and 7 deletions
35
main.go
35
main.go
|
@ -3,7 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"flag"
|
"flag"
|
||||||
|
"os"
|
||||||
|
"os/signal"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"github.com/miekg/dns"
|
"github.com/miekg/dns"
|
||||||
"github.com/outout14/sacrebleu-api/api/types"
|
"github.com/outout14/sacrebleu-api/api/types"
|
||||||
|
@ -46,13 +49,27 @@ func main() {
|
||||||
types.SQLMigrate(db)
|
types.SQLMigrate(db)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Start the DNS server
|
//Start the UDP listener
|
||||||
server := &dns.Server{Addr: conf.App.IP + ":" + strconv.Itoa(conf.App.Port), Net: "tcp"} //define the server
|
go func() {
|
||||||
logrus.WithFields(logrus.Fields{"ip": conf.App.IP, "port": conf.App.Port}).Infof("SERVER : Started") //log
|
server := &dns.Server{Addr: conf.App.IP + ":" + strconv.Itoa(conf.App.Port), Net: "udp"} //define the server
|
||||||
logrus.WithFields(logrus.Fields{"XfrIPs": conf.DNS.XfrIPs}).Debug("")
|
logrus.WithFields(logrus.Fields{"ip": conf.App.IP, "port": conf.App.Port}).Infof("SERVER : Started UDP listener") //log
|
||||||
|
if err := server.ListenAndServe(); err != nil {
|
||||||
err = server.ListenAndServe() //start it
|
logrus.Fatalf("Failed to set udp listener %s\n", err.Error())
|
||||||
utils.CheckErr(err)
|
}
|
||||||
|
}()
|
||||||
defer server.Shutdown() //shut down on application closing
|
|
||||||
|
//Start the TCP listener
|
||||||
|
go func() {
|
||||||
|
server := &dns.Server{Addr: conf.App.IP + ":" + strconv.Itoa(conf.App.Port), Net: "tcp"} //define the server
|
||||||
|
logrus.WithFields(logrus.Fields{"ip": conf.App.IP, "port": conf.App.Port}).Infof("SERVER : Started TCP listener") //log
|
||||||
|
if err := server.ListenAndServe(); err != nil {
|
||||||
|
logrus.Fatalf("Failed to set udp listener %s\n", err.Error())
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
sig := make(chan os.Signal)
|
||||||
|
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
|
||||||
|
s := <-sig
|
||||||
|
logrus.Infof("Signal (%v) received, stopping\n", s)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue