本文整理汇总了Golang中github.com/philpearl/tt_goji_middleware/base.Session类的典型用法代码示例。如果您正苦于以下问题:Golang Session类的具体用法?Golang Session怎么用?Golang Session使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Session类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Get
/*
Get the session for this request from Redis
*/
func (sh *SessionHolder) Get(c web.C, r *http.Request) (*base.Session, error) {
sessionId := sh.GetSessionId(r)
if sessionId == "" {
return nil, base.ErrorSessionNotFound
}
conn := c.Env["redis"].(redigo.Conn)
sess, err := conn.Do("GET", sessionKey(sessionId))
if err != nil {
return nil, err
}
if sess == nil {
return nil, base.ErrorSessionNotFound
}
sessionBytes, err := redigo.Bytes(sess, err)
if err != nil {
return nil, err
}
dec := gob.NewDecoder(bytes.NewReader(sessionBytes))
var session base.Session
err = dec.Decode(&session)
if err == nil {
session.SetId(sessionId)
}
return &session, err
}
开发者ID:timisbusy,项目名称:tt_goji_middleware,代码行数:32,代码来源:session.go
示例2: ResetTTL
func (sh *SessionHolder) ResetTTL(c web.C, session *base.Session) error {
sessionId := session.Id()
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("EXPIRE", sessionKey(sessionId), sh.Timeout)
return err
}
开发者ID:timisbusy,项目名称:tt_goji_middleware,代码行数:7,代码来源:session.go
示例3: Destroy
/*
Destroy deletes a session from redis
*/
func (sh *SessionHolder) Destroy(c web.C, session *base.Session) error {
sessionId := session.Id()
delete(c.Env, "session")
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("DEL", sessionKey(sessionId))
return err
}
开发者ID:timisbusy,项目名称:tt_goji_middleware,代码行数:11,代码来源:session.go
示例4: Save
/*
Save a session to postgres
*/
func (sh *SessionHolder) Save(c web.C, session *base.Session) error {
sessionId := session.Id()
// There is a potential race here if the insert fails because the session exists, but it is deleted
// before we can update it.
_, err := sh.db.Exec("INSERT INTO sessions (id, content, expires) VALUES ($1, $2, now() + $3 * interval '1 second')", sessionId, sessionValues(session.Values), sh.Timeout)
if err != nil && isAlreadyExists(err, "sessions") {
_, err = sh.db.Exec("UPDATE sessions SET content=$2, expires=now() + $3 * interval '1 second' WHERE id=$1", sessionId, sessionValues(session.Values), sh.Timeout)
}
return err
}
开发者ID:timisbusy,项目名称:tt_goji_middleware,代码行数:14,代码来源:session.go
示例5: RegenerateId
func (sh *SessionHolder) RegenerateId(c web.C, session *base.Session) (string, error) {
sessionId := session.Id()
newSessionId := sh.GenerateSessionId()
conn := c.Env["redis"].(redigo.Conn)
_, err := conn.Do("RENAME", sessionKey(sessionId), sessionKey(newSessionId))
if err == nil {
/* renaming of session key succeeded in backend... update sessionId in our struct */
session.SetId(newSessionId)
} else {
newSessionId = sessionId
}
return newSessionId, err
}
开发者ID:timisbusy,项目名称:tt_goji_middleware,代码行数:14,代码来源:session.go
注:本文中的github.com/philpearl/tt_goji_middleware/base.Session类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论