-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
95 lines (73 loc) · 2.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package main
import (
"flag"
"fmt"
"log"
"net/http"
_ "net/http/pprof" // !DEBUG
"os"
"os/signal"
"syscall"
"github.com/guerillagrow/gobox/controllers"
//"github.com/guerillagrow/gobox/custom/xsession"
"github.com/guerillagrow/gobox/lib/utils"
"github.com/guerillagrow/gobox/models"
_ "github.com/guerillagrow/gobox/routers"
"github.com/guerillagrow/beego"
)
var VERSION string
func PprofServe() {
go func() {
// !DEBUG
log.Println(http.ListenAndServe(":6060", nil))
}()
}
func main() {
utils.LocalVersion = VERSION
sigs := make(chan os.Signal, 1)
//done := make(chan bool, 1)
models.ARG_ConfigFile = flag.String("c", "./conf/raspberrypi.json", "Config file")
models.ARG_DBFile = flag.String("d", "./conf/main.db", "Database file")
models.ARG_Debug = flag.Bool("debug", false, "Debug mode")
ARG_VERSION := flag.Bool("version", false, "Show version")
flag.Parse()
if *ARG_VERSION {
fmt.Println(VERSION)
return
}
if *models.ARG_Debug == true {
PprofServe()
}
models.Init() // Initialize models database etc.
go func() {
sig := <-sigs
if sig == os.Interrupt || sig == os.Kill || sig == syscall.SIGTERM {
models.GoBox.Stop()
os.Exit(1)
}
//done <- true
}()
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
cfgDebugFlag, cderr := models.BoxConfig.GetBool("debug_mode")
if cderr == nil && cfgDebugFlag == true && !*models.ARG_Debug {
models.ARG_Debug = &cfgDebugFlag
PprofServe()
}
models.GoBox.Start()
beego.BConfig.WebConfig.Session.SessionOn = true
beego.BConfig.WebConfig.Session.SessionAutoSetCookie = true
beego.BConfig.MaxMemory = 1 << 26
//beego.BConfig.CopyRequestBody = true // required for json request bodies!
/*sessionconf := &session.ManagerConfig{
CookieName: "gobox_sess",
CookieLifeTime: 3600,
Maxlifetime: 3600,
Gclifetime: 3600 / 4,
ProviderConfig: "./tmp",
EnableSetCookie: true,
}
beego.GlobalSessions, _ = session.NewManager("file", sessionconf) // !NOTE: Beego BUG: File based sessions are not saved correctly when using ajax requests
go beego.GlobalSessions.GC()*/
beego.ErrorController(&controllers.ErrorController{})
beego.Run()
}