|
|
|
@ -7,16 +7,16 @@ import (
|
|
|
|
|
type Session struct {
|
|
|
|
|
sync.RWMutex // 数据锁
|
|
|
|
|
|
|
|
|
|
id int64 // Session全局唯一ID
|
|
|
|
|
uid string // 用户ID,不绑定的情况下与sid一致
|
|
|
|
|
data map[string]interface{} // session数据存储(内存)
|
|
|
|
|
id int64 // Session全局唯一ID
|
|
|
|
|
uid string // 用户ID,不绑定的情况下与sid一致
|
|
|
|
|
data map[string]any // session数据存储(内存)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func NewSession(id int64) *Session {
|
|
|
|
|
return &Session{
|
|
|
|
|
id: id,
|
|
|
|
|
uid: "",
|
|
|
|
|
data: make(map[string]interface{}),
|
|
|
|
|
data: make(map[string]any),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -36,7 +36,7 @@ func (s *Session) Bind(uid string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attribute 获取指定key对应参数
|
|
|
|
|
func (s *Session) Attribute(key string) interface{} {
|
|
|
|
|
func (s *Session) Attribute(key string) any {
|
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
@ -65,7 +65,7 @@ func (s *Session) Exists(key string) bool {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Attributes 获取所有参数
|
|
|
|
|
func (s *Session) Attributes() map[string]interface{} {
|
|
|
|
|
func (s *Session) Attributes() map[string]any {
|
|
|
|
|
s.RLock()
|
|
|
|
|
defer s.RUnlock()
|
|
|
|
|
|
|
|
|
@ -81,7 +81,7 @@ func (s *Session) RemoveAttribute(key string) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// SetAttribute 设置参数
|
|
|
|
|
func (s *Session) SetAttribute(key string, value interface{}) {
|
|
|
|
|
func (s *Session) SetAttribute(key string, value any) {
|
|
|
|
|
s.Lock()
|
|
|
|
|
defer s.Unlock()
|
|
|
|
|
|
|
|
|
@ -95,7 +95,7 @@ func (s *Session) Invalidate() {
|
|
|
|
|
|
|
|
|
|
s.id = 0
|
|
|
|
|
s.uid = ""
|
|
|
|
|
s.data = make(map[string]interface{})
|
|
|
|
|
s.data = make(map[string]any)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Close 关闭
|
|
|
|
|