我们可以controller获得Ctx,然后进行后续操作,比如设置cookie。

func (l *LoginController) Post() { l.Ctx.SetCookie("username", username, maxAge, "/") }

同时,我们也可以通过获取cookie中的值:

func (l *LoginController) Post() { l.ctx.Request.Cookie("username") } 

但是,在不同版本中对应的ctx的类型和package有所不同。

在老版本中是通过引入beego包就可以直接使用beego.Context获取的到。
比如:

import "github.com/astaxie/beego"
func checkAccount(ctx *beego.Context) bool {}

但是,在新版本中只能新引入另外一个包来获取:

import "github.com/astaxie/beego/context"
func checkAccount(ctx *context.Context) bool {}

因此在升级版本的过程中需要留意此处,否则会无法找到对应的定义。