-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
42 lines (33 loc) · 982 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
package main
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/juanfgs/blog/helpers"
_ "github.com/juanfgs/blog/models"
_ "github.com/juanfgs/blog/routers"
)
var sessionName = beego.AppConfig.String("SessionName")
func main() {
var FilterUser = func(ctx *context.Context) {
_, ok := ctx.Input.Session(sessionName).(int)
if !ok && ctx.Input.URI() != "/login" && ctx.Input.URI() != "/register" {
ctx.Redirect(302, "/login")
}
}
beego.AddFuncMap("equals", equals)
beego.AddFuncMap("renderPost", helpers.RenderPost)
beego.AddFuncMap("renderSafeMarkDown", helpers.RenderSafeMarkDown)
beego.AddFuncMap("renderMarkDown", helpers.RenderMarkDown)
beego.InsertFilter("/admin/", beego.BeforeRouter, FilterUser)
beego.InsertFilter("/admin/*", beego.BeforeRouter, FilterUser)
beego.Run()
}
func equals(a interface{}, b interface{}) bool {
if a == nil || b == nil {
return false
}
if a == b {
return true
}
return false
}