-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
45 lines (36 loc) · 887 Bytes
/
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
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
"beego-demo/controllers"
_ "beego-demo/routers"
"github.com/astaxie/beego"
_ "github.com/astaxie/beego/session/redis"
)
func handleSignals(c chan os.Signal) {
switch <-c {
case syscall.SIGINT, syscall.SIGTERM:
fmt.Println("Shutdown quickly, bye...")
case syscall.SIGQUIT:
fmt.Println("Shutdown gracefully, bye...")
// do graceful shutdown
}
os.Exit(0)
}
func main() {
graceful, _ := beego.AppConfig.Bool("graceful")
if !graceful {
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
go handleSignals(sigs)
}
beego.SetLogger("file", `{"filename":"logs/test.log"}`)
mode := beego.AppConfig.String("runmode")
if mode == "prod" {
beego.SetLevel(beego.LevelInformational)
}
beego.ErrorController(&controllers.ErrorController{})
beego.Run()
}