liteblog/controllers/base.go

25 lines
526 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package controllers
import (
"github.com/astaxie/beego"
"log"
)
type NestPreparer interface {
NestPrepare()
}
type BaseController struct {
beego.Controller
}
func (ctx *BaseController) Prepare() {
log.Println("BaseController")
// 判断子类是否实现了NestPreparer接口如果实现了就调用接口方法。
// 将页面路径保存到path变量中
ctx.Data["Path"] = ctx.Ctx.Request.RequestURI
ctx.Data["Username"] = "xxxx"
if app, ok := ctx.AppController.(NestPreparer); ok {
app.NestPrepare()
}
}