-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
40 lines (34 loc) · 1.05 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
package main
import (
"html/template"
"net/http"
_ "gowork/initial"
_ "gowork/routers"
_ "gowork/utils"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
"github.com/astaxie/beego/logs"
)
func main() {
logs.SetLogger(logs.AdapterFile,`{"filename":"logs/gowork.log","level":7,"maxlines":0,"maxsize":0,"daily":true,"maxdays":10}`)
beego.InsertFilter("/*", beego.BeforeRouter, FilterUser)
beego.ErrorHandler("404", page_not_found)
beego.ErrorHandler("401", page_note_permission)
beego.Run()
}
var FilterUser = func(ctx *context.Context) {
_, ok := ctx.Input.Session("userLogin").(string)
if !ok && ctx.Request.RequestURI != "/login" {
ctx.Redirect(302, "/login")
}
}
func page_not_found(rw http.ResponseWriter, r *http.Request) {
t, _ := template.New("404.tpl").ParseFiles("views/404.tpl")
data := make(map[string]interface{})
t.Execute(rw, data)
}
func page_note_permission(rw http.ResponseWriter, r *http.Request) {
t, _ := template.New("401.tpl").ParseFiles("views/401.tpl")
data := make(map[string]interface{})
t.Execute(rw, data)
}