This repository has been archived by the owner on Jun 21, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.go
78 lines (67 loc) · 1.53 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
package main
import (
"fmt"
"io"
"os"
"runtime"
"strings"
"github.com/Unknwon/i18n"
"github.com/go-xweb/log"
"github.com/go-xweb/xweb"
"github.com/go-xorm/website/actions"
"github.com/go-xorm/website/models"
)
const (
APP_VER = "0.4.0213"
)
func main() {
defer func() {
if res := recover(); res != nil {
content := fmt.Sprintf("Crashed with error: %v", res)
for i := 1; ; i += 1 {
_, file, line, ok := runtime.Caller(i)
if !ok {
break
} else {
content += "\n"
}
content += fmt.Sprintf("%v %v", file, line)
}
fmt.Println(content)
}
}()
models.InitModels()
mode, _ := models.Cfg.GetValue("app", "run_mode")
var isPro bool = true
if mode == "dev" {
log.SetOutputLevel(log.Ldebug)
isPro = false
}
log.Info("run in " + mode + " mode")
f, err := os.Create("./website.log")
if err != nil {
fmt.Println(err)
return
}
log.SetOutput(io.MultiWriter(f, os.Stdout))
xweb.SetLogger(log.Std)
actions.InitApp()
// Register routers.
xweb.AddAction(&actions.HomeAction{})
xweb.AutoAction(&actions.DocsAction{}, &actions.LinkAction{})
xweb.AddTmplVars(&xweb.T{
"i18n": i18n.Tr,
"IsPro": isPro,
"AppVer": APP_VER,
"XwebVer": xweb.Version,
"GoVer": strings.Trim(runtime.Version(), "go"),
})
port, _ := models.Cfg.GetValue("app", "http_port")
usessl, _ := models.Cfg.GetValue("app", "ssl")
if usessl == "true" {
tlsCfg, _ := xweb.SimpleTLSConfig("cert.pem", "key.pem")
xweb.RunTLS(fmt.Sprintf(":%v", port), tlsCfg)
} else {
xweb.Run(fmt.Sprintf(":%v", port))
}
}