memory

package
v0.0.3 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrSessionNotFound = errors.New("session not found")
	ErrSessionExpired  = errors.New("session expired")
)

Functions

This section is empty.

Types

type Provider

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

Provider 内存 Session Provider 注意:仅用于开发测试,生产环境请使用 Redis

func NewProvider

func NewProvider(jwtKey string, accessExpire, refreshExpire time.Duration, carrier session.TokenCarrier) *Provider

NewProvider 创建内存 Session Provider jwtKey: JWT 签名密钥 accessExpire: Access Token 过期时间(建议 15 分钟 - 2 小时) refreshExpire: Refresh Token 过期时间(建议 7 天 - 30 天) carrier: Token 载体(Header 或 Cookie)

func (*Provider) Destroy

func (p *Provider) Destroy(ctx *gctx.Context) error

Destroy 销毁 Session

func (*Provider) Get

func (p *Provider) Get(ctx *gctx.Context) (session.Session, error)

Get 获取已存在的 Session

func (*Provider) NewSession

func (p *Provider) NewSession(ctx *gctx.Context, userId string, jwtData map[string]string, sessData map[string]any) (session.Session, error)

NewSession 创建新的 Session

func (*Provider) RenewToken

func (p *Provider) RenewToken(ctx *gctx.Context) error

RenewToken 刷新 Token(使用 Refresh Token 获取新的 Access Token)

type Session

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

Session 内存 Session 实现

func (*Session) Claims

func (s *Session) Claims() *jwt.Claims

Claims 获取 JWT Claims

func (*Session) Del

func (s *Session) Del(ctx context.Context, key string) error

Del 删除 Session 数据

func (*Session) Destroy

func (s *Session) Destroy(ctx context.Context) error

Destroy 销毁 Session(内存实现中只是标记为过期)

func (*Session) Get

func (s *Session) Get(ctx context.Context, key string) (any, error)

Get 获取 Session 数据

func (*Session) Refresh

func (s *Session) Refresh(ctx context.Context) error

Refresh 刷新 Session 过期时间

func (*Session) Set

func (s *Session) Set(ctx context.Context, key string, val any) error

Set 设置 Session 数据

Jump to

Keyboard shortcuts

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