## 一、main.go中的main中添加
~~~
beego.InsertFilter("/mains/*", beego.BeforeRouter, utils.CmsLoginFilter)
~~~
实例:
~~~
func main() {
beego.InsertFilter("/mains/*", beego.BeforeRouter, utils.CmsLoginFilter)
beego.Run()
}
~~~
过滤器代码:
~~~
package utils
import (
"github.com/astaxie/beego"
"github.com/astaxie/beego/context"
)
func CmsLoginFilter(ctx *context.Context) {
cms_user_name := ctx.Input.Session("user_name")
if cms_user_name == nil {
ctx.Redirect(302, beego.URLFor("LoginController.Get"))
}
}
~~~