session

package
v0.1.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionKeyPrefix = "session:" // Storage key prefix | 存储键前缀
)

Constants for session keys | Session键常量

Variables

View Source
var (
	ErrSessionNotFound    = fmt.Errorf("session not found")
	ErrInvalidSessionData = fmt.Errorf("invalid session data")
)

Error variables | 错误变量

Functions

This section is empty.

Types

type Session

type Session struct {
	ID         string         `json:"id"`         // Session ID | Session标识
	CreateTime int64          `json:"createTime"` // Creation time | 创建时间
	Data       map[string]any `json:"data"`       // Session data | 数据
	// contains filtered or unexported fields
}

Session Session object for storing user data | 会话对象,用于存储用户数据

func Load

func Load(id string, storage adapter.Storage, prefix string) (*Session, error)

Load Loads session from storage | 从存储加载

func NewSession

func NewSession(id string, storage adapter.Storage, prefix string) *Session

NewSession Creates a new session | 创建新的Session

func (*Session) Clear

func (s *Session) Clear() error

Clear Clears all data | 清空所有数据

func (*Session) Delete

func (s *Session) Delete(key string) error

Delete 删除键

func (*Session) Destroy

func (s *Session) Destroy() error

Destroy Destroys session | 销毁Session

func (*Session) Get

func (s *Session) Get(key string) (any, bool)

Get Gets value | 获取值

func (*Session) GetBool

func (s *Session) GetBool(key string) bool

GetBool 获取布尔值

func (*Session) GetInt

func (s *Session) GetInt(key string) int

GetInt gets integer value | 获取整数值

func (*Session) GetInt64

func (s *Session) GetInt64(key string) int64

GetInt64 获取int64值

func (*Session) GetString

func (s *Session) GetString(key string) string

GetString gets string value | 获取字符串值

func (*Session) Has

func (s *Session) Has(key string) bool

Has 检查键是否存在

func (*Session) IsEmpty

func (s *Session) IsEmpty() bool

IsEmpty Checks if session has no data | 检查Session是否为空

func (*Session) Keys

func (s *Session) Keys() []string

Keys Gets all keys | 获取所有键

func (*Session) Set

func (s *Session) Set(key string, value any) error

Set Sets value | 设置值

func (*Session) Size

func (s *Session) Size() int

Size Gets data count | 获取数据数量

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL