-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (55 loc) · 1.24 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
package main
import (
"html/template"
"os"
"strings"
_ "techbase/routers"
"techbase/utils"
"time"
"github.com/astaxie/beego"
"github.com/beego/i18n"
)
const (
version = "0.1.24.1105"
)
func main() {
beego.Info(beego.BConfig.AppName, version)
beego.Run()
}
func init() {
// 日志级别
if beego.BConfig.RunMode == "dev" {
beego.SetLevel(beego.LevelDebug)
} else {
beego.SetLevel(beego.LevelNotice)
}
os.Mkdir("./logs", os.ModePerm)
//日志文件名
beego.BeeLogger.SetLogger("file", `{"filename": "logs/log.log"}`)
initStaticPath()
initTemplateExt()
initFuncMap()
}
// 初始化模板函数
func initFuncMap() {
beego.AddFuncMap("i18n", i18n.Tr)
beego.AddFuncMap("loadtimes", loadtimes)
beego.AddFuncMap("split", strings.Split)
beego.AddFuncMap("m2t", utils.Msec2Time)
beego.AddFuncMap("css", func(s string) template.CSS {
return template.CSS(s)
})
}
// 初始化静态目录
func initStaticPath() {
beego.SetStaticPath("/html", "html")
beego.SetStaticPath("/upload", beego.AppConfig.String("UploadPhysicalPath")) //"upload"
}
// 初始化模板后缀
func initTemplateExt() {
//beego.AddTemplateExt(".html")
}
// 引用自beego官网
func loadtimes(t time.Time) int {
return int(time.Now().Sub(t).Nanoseconds() / 1e6)
}