diff --git a/controller.go b/controller.go index ccf213aa..b7804f33 100644 --- a/controller.go +++ b/controller.go @@ -275,21 +275,21 @@ func (c *Controller) StartSession() session.SessionStore { return c.CruSession } -func (c *Controller) SetSession(name string, value interface{}) { +func (c *Controller) SetSession(name interface{}, value interface{}) { if c.CruSession == nil { c.StartSession() } c.CruSession.Set(name, value) } -func (c *Controller) GetSession(name string) interface{} { +func (c *Controller) GetSession(name interface{}) interface{} { if c.CruSession == nil { c.StartSession() } return c.CruSession.Get(name) } -func (c *Controller) DelSession(name string) { +func (c *Controller) DelSession(name interface{}) { if c.CruSession == nil { c.StartSession() } diff --git a/session/sess_file.go b/session/sess_file.go index d5ab6b4a..0994c83a 100644 --- a/session/sess_file.go +++ b/session/sess_file.go @@ -58,11 +58,13 @@ func (fs *FileSessionStore) SessionRelease() { } func (fs *FileSessionStore) updatecontent() { - b, err := encodeGob(fs.values) - if err != nil { - return + if len(fs.values) > 0 { + b, err := encodeGob(fs.values) + if err != nil { + return + } + fs.f.Write(b) } - fs.f.Write(b) } type FileProvider struct { diff --git a/session/sess_mysql.go b/session/sess_mysql.go index a55d5612..217227e9 100644 --- a/session/sess_mysql.go +++ b/session/sess_mysql.go @@ -55,11 +55,13 @@ func (st *MysqlSessionStore) SessionID() string { } func (st *MysqlSessionStore) updatemysql() { - b, err := encodeGob(st.values) - if err != nil { - return + if len(st.values) > 0 { + b, err := encodeGob(st.values) + 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() {