iedc-go/session.go

57 lines
900 B
Go
Raw Permalink Normal View History

2017-08-04 08:20:59 +00:00
package hotime
2021-05-23 23:27:41 +00:00
import (
. "./cache"
. "./common"
)
2017-08-10 10:14:56 +00:00
//session对象
2017-08-04 08:20:59 +00:00
type SessionIns struct {
*HoTimeCache
SessionId string
2017-08-04 08:20:59 +00:00
Map
2021-05-23 23:27:41 +00:00
ContextBase
2017-08-04 08:20:59 +00:00
}
func (that *SessionIns) set() {
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
2017-08-04 08:20:59 +00:00
}
func (that *SessionIns) Session(key string, data ...interface{}) *Obj {
2017-08-04 08:20:59 +00:00
if that.Map == nil {
that.get()
2017-08-04 08:20:59 +00:00
}
2017-08-10 10:14:56 +00:00
if len(data) != 0 {
if data[0] == nil {
delete(that.Map, key)
that.set()
2017-08-10 10:14:56 +00:00
} else {
that.Map[key] = data[0]
that.set()
2017-08-04 08:20:59 +00:00
}
2017-08-10 10:14:56 +00:00
return &Obj{Data: nil}
2017-08-04 08:20:59 +00:00
}
return &Obj{Data: that.Map.Get(key)}
2017-08-04 08:20:59 +00:00
}
func (that *SessionIns) get() {
2017-08-04 08:20:59 +00:00
that.Map = that.HoTimeCache.Session(HEAD_SESSION_ADD + that.SessionId).ToMap()
if that.Map != nil {
return
2017-08-04 08:20:59 +00:00
}
that.Map = Map{}
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
2017-08-04 08:20:59 +00:00
return
}
func (that *SessionIns) Init(cache *HoTimeCache) {
that.HoTimeCache = cache
2017-08-10 10:14:56 +00:00
}