-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
executable file
·50 lines (45 loc) · 1.14 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
package main
import (
"github.com/astaxie/beego"
_ "blog/models"
_ "blog/routers"
"github.com/astaxie/beego/logs"
"strings"
"strconv"
_ "blog/controllers/ipfilter"
)
func initLogger() {
var consoleconfig=`{"level":7}`
logs.SetLogger(logs.AdapterConsole,consoleconfig)
var fileconfig = `{"filename":"log/log.log","level":7}`
logs.SetLogger(logs.AdapterFile,fileconfig)
//var mailconfig = `{"username":"[email protected]",
// "password":"xxxxxxxx",
// "host":"smtp.gmail.com:587",
// "sendTos":["[email protected]"]}`
//logs.SetLogger(logs.AdapterMail,mailconfig)
logs.Async(1e3)
}
//添加自定义模板函数
func hasPermission(permissionlist map[string]int, value int) (out bool) {
for _, id := range permissionlist {
if value == id {
return true
}
}
return false
}
func hasPermissionstr(permissionlist string, value int) (out bool) {
for _, id := range strings.Split(permissionlist, "|") {
if id == strconv.Itoa(value) {
return true
}
}
return false
}
func main() {
initLogger()
beego.AddFuncMap("haspermission", hasPermission)
beego.AddFuncMap("haspermissionstr", hasPermissionstr)
beego.Run()
}