1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 22:51:29 +00:00

update session's key from string to interface

This commit is contained in:
astaxie 2013-05-13 23:30:50 +08:00
parent 719f94b35f
commit d8e1f31cc9
3 changed files with 15 additions and 11 deletions

View File

@ -275,21 +275,21 @@ func (c *Controller) StartSession() session.SessionStore {
return c.CruSession return c.CruSession
} }
func (c *Controller) SetSession(name string, value interface{}) { func (c *Controller) SetSession(name interface{}, value interface{}) {
if c.CruSession == nil { if c.CruSession == nil {
c.StartSession() c.StartSession()
} }
c.CruSession.Set(name, value) c.CruSession.Set(name, value)
} }
func (c *Controller) GetSession(name string) interface{} { func (c *Controller) GetSession(name interface{}) interface{} {
if c.CruSession == nil { if c.CruSession == nil {
c.StartSession() c.StartSession()
} }
return c.CruSession.Get(name) return c.CruSession.Get(name)
} }
func (c *Controller) DelSession(name string) { func (c *Controller) DelSession(name interface{}) {
if c.CruSession == nil { if c.CruSession == nil {
c.StartSession() c.StartSession()
} }

View File

@ -58,11 +58,13 @@ func (fs *FileSessionStore) SessionRelease() {
} }
func (fs *FileSessionStore) updatecontent() { func (fs *FileSessionStore) updatecontent() {
b, err := encodeGob(fs.values) if len(fs.values) > 0 {
if err != nil { b, err := encodeGob(fs.values)
return if err != nil {
return
}
fs.f.Write(b)
} }
fs.f.Write(b)
} }
type FileProvider struct { type FileProvider struct {

View File

@ -55,11 +55,13 @@ func (st *MysqlSessionStore) SessionID() string {
} }
func (st *MysqlSessionStore) updatemysql() { func (st *MysqlSessionStore) updatemysql() {
b, err := encodeGob(st.values) if len(st.values) > 0 {
if err != nil { b, err := encodeGob(st.values)
return if err != nil {
return
}
st.c.Exec("UPDATE session set `session_data`= ? where session_key=?", b, st.sid)
} }
st.c.Exec("UPDATE session set `session_data`= ? where session_key=?", b, st.sid)
} }
func (st *MysqlSessionStore) SessionRelease() { func (st *MysqlSessionStore) SessionRelease() {