iedc-go/vendor/code.hoteas.com/golang/hotime/session.go

57 lines
956 B
Go
Raw Permalink Normal View History

2023-03-02 19:12:15 +00:00
package hotime
import (
. "code.hoteas.com/golang/hotime/cache"
. "code.hoteas.com/golang/hotime/common"
)
//session对象
type SessionIns struct {
*HoTimeCache
SessionId string
Map
ContextBase
}
func (that *SessionIns) set() {
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
}
func (that *SessionIns) Session(key string, data ...interface{}) *Obj {
if that.Map == nil {
that.get()
}
if len(data) != 0 {
if data[0] == nil {
delete(that.Map, key)
that.set()
} else {
that.Map[key] = data[0]
that.set()
}
return &Obj{Data: nil}
}
return &Obj{Data: that.Map.Get(key)}
}
func (that *SessionIns) get() {
that.Map = that.HoTimeCache.Session(HEAD_SESSION_ADD + that.SessionId).ToMap()
if that.Map != nil {
return
}
that.Map = Map{}
that.HoTimeCache.Session(HEAD_SESSION_ADD+that.SessionId, that.Map)
return
}
func (that *SessionIns) Init(cache *HoTimeCache) {
that.HoTimeCache = cache
}