d8e1f31c by astaxie

update session's key from string to interface

1 parent 719f94b3
...@@ -275,21 +275,21 @@ func (c *Controller) StartSession() session.SessionStore { ...@@ -275,21 +275,21 @@ func (c *Controller) StartSession() session.SessionStore {
275 return c.CruSession 275 return c.CruSession
276 } 276 }
277 277
278 func (c *Controller) SetSession(name string, value interface{}) { 278 func (c *Controller) SetSession(name interface{}, value interface{}) {
279 if c.CruSession == nil { 279 if c.CruSession == nil {
280 c.StartSession() 280 c.StartSession()
281 } 281 }
282 c.CruSession.Set(name, value) 282 c.CruSession.Set(name, value)
283 } 283 }
284 284
285 func (c *Controller) GetSession(name string) interface{} { 285 func (c *Controller) GetSession(name interface{}) interface{} {
286 if c.CruSession == nil { 286 if c.CruSession == nil {
287 c.StartSession() 287 c.StartSession()
288 } 288 }
289 return c.CruSession.Get(name) 289 return c.CruSession.Get(name)
290 } 290 }
291 291
292 func (c *Controller) DelSession(name string) { 292 func (c *Controller) DelSession(name interface{}) {
293 if c.CruSession == nil { 293 if c.CruSession == nil {
294 c.StartSession() 294 c.StartSession()
295 } 295 }
......
...@@ -58,11 +58,13 @@ func (fs *FileSessionStore) SessionRelease() { ...@@ -58,11 +58,13 @@ func (fs *FileSessionStore) SessionRelease() {
58 } 58 }
59 59
60 func (fs *FileSessionStore) updatecontent() { 60 func (fs *FileSessionStore) updatecontent() {
61 b, err := encodeGob(fs.values) 61 if len(fs.values) > 0 {
62 if err != nil { 62 b, err := encodeGob(fs.values)
63 return 63 if err != nil {
64 return
65 }
66 fs.f.Write(b)
64 } 67 }
65 fs.f.Write(b)
66 } 68 }
67 69
68 type FileProvider struct { 70 type FileProvider struct {
......
...@@ -55,11 +55,13 @@ func (st *MysqlSessionStore) SessionID() string { ...@@ -55,11 +55,13 @@ func (st *MysqlSessionStore) SessionID() string {
55 } 55 }
56 56
57 func (st *MysqlSessionStore) updatemysql() { 57 func (st *MysqlSessionStore) updatemysql() {
58 b, err := encodeGob(st.values) 58 if len(st.values) > 0 {
59 if err != nil { 59 b, err := encodeGob(st.values)
60 return 60 if err != nil {
61 return
62 }
63 st.c.Exec("UPDATE session set `session_data`= ? where session_key=?", b, st.sid)
61 } 64 }
62 st.c.Exec("UPDATE session set `session_data`= ? where session_key=?", b, st.sid)
63 } 65 }
64 66
65 func (st *MysqlSessionStore) SessionRelease() { 67 func (st *MysqlSessionStore) SessionRelease() {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!