session

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package session 提供会话管理功能。

Package session 提供内存会话存储抽象层。

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyNotFound = errors.New("session: key not found")
	ErrExpired     = errors.New("session: key expired")
)

错误定义

View Source
var GinStore sessions.Store

GinStore 全局 Gin 会话存储实例(用于 HTTP 会话)。

Functions

func InitSessionStore

func InitSessionStore() error

InitSessionStore 初始化会话存储。 STX 默认使用内存 SessionStore + Cookie Gin 会话。

Types

type MemoryStore

type MemoryStore struct {
	// contains filtered or unexported fields
}

MemoryStore 内存会话存储实现。

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore 创建新的内存存储实例。

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(ctx context.Context, key string) error

Delete 从内存中删除指定 key。

func (*MemoryStore) Exists

func (m *MemoryStore) Exists(ctx context.Context, key string) (bool, error)

Exists 检查 key 是否存在于内存中。

func (*MemoryStore) Get

func (m *MemoryStore) Get(ctx context.Context, key string) (any, error)

Get 从内存中获取指定 key 的值。

func (*MemoryStore) Set

func (m *MemoryStore) Set(ctx context.Context, key string, value any, expiration time.Duration) error

Set 将值存储到内存中。

type SessionStore

type SessionStore interface {
	Get(ctx context.Context, key string) (any, error)
	Set(ctx context.Context, key string, value any, expiration time.Duration) error
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
}

SessionStore 会话存储接口。

var Store SessionStore

Store 全局会话存储实例。

type StoreType

type StoreType string

StoreType 会话存储类型。

const (
	// StoreTypeMemory 内存存储。
	StoreTypeMemory StoreType = "memory"
)

func GetStoreType

func GetStoreType() StoreType

GetStoreType 获取当前会话存储类型。

Jump to

Keyboard shortcuts

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