您的位置:首页 > 编程语言 > Go语言

BEEGO session写入,读取

2016-07-12 17:03 429 查看
package controllers

import (
//"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 Locals
type LocalController struct {
beego.Controller
}

// @Title createLocal
// @Description request interface
// @Param	body		body 	models.Local	true		"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))
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: