198 Star 559 Fork 252

lock-li / opms

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
main.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
www 提交于 2016-10-31 21:48 . new version 1.2 for notice,check work etc.
package main
import (
"html/template"
"net/http"
_ "opms/initial"
_ "opms/routers"
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
)
func main() {
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{})
//data["content"] = "page not found"
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{})
//data["content"] = "你没有权限访问此页面,请联系超级管理员。或去<a href='/'>开启我的OPMS之旅</a>。"
t.Execute(rw, data)
}
Go
1
https://gitee.com/lock-upme/opms.git
git@gitee.com:lock-upme/opms.git
lock-upme
opms
opms
master

搜索帮助