Documentation
¶
Overview ¶
Package session 提供会话管理功能,支持内存和Redis存储
Package session 提供会话管理功能,支持内存和Redis存储 ¶
Package session 提供会话管理功能,支持内存和Redis存储 ¶
Package session 提供会话管理功能,支持内存和Redis存储
Index ¶
- Constants
- Variables
- func Emit(event Event, value any)
- func Errorf(format any, args ...any) error
- func Listen(event Event, listener Listener)
- func NewMemorySetter(id string, data any) storage.Setter
- func On(event Event, listener Listener)
- type Data
- func (this *Data) Atomic() int32
- func (this *Data) Delete(key string, done ...func())
- func (this *Data) Get(key string) any
- func (this *Data) GetFloat64(key string) float64
- func (this *Data) GetInt(key string) int
- func (this *Data) GetInt32(key string) int32
- func (this *Data) GetInt64(key string) int64
- func (this *Data) GetString(key string) string
- func (this *Data) Heartbeat(v ...int32) int32
- func (this *Data) Id() string
- func (this *Data) Index() int32
- func (this *Data) Is(v *Data) bool
- func (this *Data) KeepAlive()
- func (this *Data) Mutex(cb func(Setter))
- func (this *Data) Range(cb func(key string, value any) bool)
- func (this *Data) Reset()
- func (this *Data) Set(key string, value any, done ...func()) any
- func (this *Data) UUID() string
- func (this *Data) Update(data map[string]any, done ...func())
- func (this *Data) Values() values.Values
- type Event
- type Listener
- type Memory
- func (this *Memory) Create(uuid string, data map[string]any) (p *Data, err error)
- func (this *Memory) Delete(d *Data) error
- func (this *Memory) Get(id string) (data *Data, err error)
- func (this *Memory) Heartbeat(i any)
- func (this *Memory) New(p *Data) error
- func (this *Memory) Update(p *Data, data map[string]any) (err error)
- type Redis
- type Session
- func (this *Session) Create(uuid string, data map[string]any) (token string, err error)
- func (this *Session) Delete() (err error)
- func (this *Session) New(data *Data) (token string, err error)
- func (this *Session) Refresh() (string, error)
- func (this *Session) Release()
- func (this *Session) Set(key string, val any)
- func (this *Session) Token() (string, error)
- func (this *Session) Update(vs map[string]any)
- func (this *Session) Verify(token string) (err error)
- type Setter
- type Storage
Constants ¶
View Source
const ContextRandomStringLength = 6
ContextRandomStringLength Token 前缀随机串长度
View Source
const TokenSecretName = "_TS_"
Variables ¶
View Source
var ( ErrorStorageEmpty = values.Errorf(202, "session Storage not set") ErrorSessionEmpty = values.Errorf(203, "session token empty") ErrorSessionNotCreate = values.Errorf(204, "session not create") ErrorSessionNotExist = values.Errorf(205, "session not exist") ErrorSessionExpired = values.Errorf(206, "session expire") ErrorSessionIllegal = values.Errorf(207, "session illegal") ErrorSessionUnknown = values.Errorf(208, "session unknown error") ErrorSessionReplaced = values.Errorf(209, "session replaced") )
View Source
var Heartbeat = heartbeat{}
Heartbeat 全局心跳管理器,只需启动一次
View Source
var MaxDataIndex = int32(math.MaxInt32 - 1000)
View Source
var Options = struct { Name string // session cookie name MaxAge int64 // 有效期(秒),0 = 不过期 Storage Storage // 存储后端 Heartbeat int32 // 心跳间隔(秒),用于内存后端自动清理过期会话 }{ Name: "_cookie_vars", MaxAge: 3600, Heartbeat: 10, }
Options 全局配置
Functions ¶
func NewMemorySetter ¶ added in v1.6.0
NewMemorySetter 内存后端的 Setter 工厂 将传入的 data 适配为 *Data 并重置 id 为 storage 分配的 token
Types ¶
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data 用户登录信息,不要直接修改 Player.Values 信息
func (*Data) GetFloat64 ¶ added in v1.6.8
GetFloat64 获取指定键的浮点数值
type Memory ¶
type Redis ¶
type Redis struct {
// contains filtered or unexported fields
}
type Session ¶
type Session struct {
*Data
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.