-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
54 lines (43 loc) · 1.13 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
53
54
package main
import (
"os"
"os/signal"
"syscall"
"time"
"github.com/astaxie/beego"
"github.com/mlgd/goHaxServer/lib/dns"
_ "github.com/mlgd/goHaxServer/routers"
)
func main() {
// Logs file
if _, err := os.Stat("log"); os.IsNotExist(err) {
err = os.MkdirAll("log", 0755)
}
beego.SetLogger("file", `{"filename":"log/`+beego.AppConfig.String("appname")+`.log"}`)
beego.SetLogFuncCall(true)
// Signal for stop program
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
signal.Notify(c, syscall.SIGTERM)
signal.Notify(c, syscall.SIGKILL)
go func() {
<-c
if beego.AppConfig.DefaultBool("enablednsserver", false) {
beego.Info("DNS server Stopping")
dns.StopServer()
}
beego.Info("http server Stopping")
time.Sleep(50 * time.Millisecond)
os.Exit(0)
}()
beego.AddAPPStartHook(appStart)
beego.Run()
}
func appStart() error {
dns.SetFilterAddresses(beego.AppConfig.DefaultStrings("dnsfilteraddresses", []string{}))
if beego.AppConfig.DefaultBool("enablednsserver", false) {
dns.StartServer(beego.AppConfig.DefaultBool("enablednsfilter", false))
beego.Info("DNS server Running")
}
return nil
}