BEEGO session写入,读取

来源:互联网 发布:广州优化网站 编辑:程序博客网 时间:2024/06/06 14:06
package controllersimport (//"encoding/json""github.com/astaxie/beego""github.com/astaxie/beego/cache"_ "github.com/astaxie/beego/cache/redis""github.com/astaxie/beego/session""github.com/garyburd/redigo/redis")func init() {globalSessionsTest, _ = session.NewManager("memory", `{"cookieName":"gosessionid","gclifetime":3600}`)go globalSessionsTest.GC()}var globalSessionsTest *session.Manager// Operations about Localstype LocalController struct {beego.Controller}// @Title createLocal// @Description request interface// @Parambodybody models.Localtrue"body for proxy content"// @Success 200 {object} models.Local// @Failure 403 :uid is empty// @router / [post]func (this *LocalController) Oauth() {var (appid,pid,sign,action string)this.Ctx.Input.Bind(&pid, "pid")this.Ctx.Input.Bind(&appid, "app_id")this.Ctx.Input.Bind(&sign, "sign")this.Ctx.Input.Bind(&action, "action")/** * 参数验证 */if len(sign) == 0 || len(action) == 0 || len(appid) == 0 || len(pid) == 0 {this.Data["json"] = JsonFormat(SYS_MISS_PARAMS, "miss params", nil)this.ServeJSON()}sess, _ := globalSessionsTest.SessionStart(this.Ctx.ResponseWriter, this.Ctx.Request)sess.Set("Session", "set session")sessionValue := sess.Get("Session")beego.Notice("session:")beego.Notice(sessionValue.(string))}

1 0