store

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package store defines auth session persistence used by auth/jwt. Package store 定义 auth/jwt 使用的认证会话持久化。

Index

Constants

This section is empty.

Variables

View Source
var ErrStoreUnavailable = errors.New("token store unavailable")

Functions

This section is empty.

Types

type MemoryStore

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

MemoryStore keeps sessions in memory. MemoryStore 在内存中保存 session。

func NewMemoryStore

func NewMemoryStore() *MemoryStore

NewMemoryStore returns an in-memory SessionStore. NewMemoryStore 返回内存版 SessionStore。

func (*MemoryStore) BumpUserVersion

func (s *MemoryStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)

BumpUserVersion invalidates all sessions for userID. BumpUserVersion 通过提升版本使 userID 的全部 session 失效。

func (*MemoryStore) CreateSession

func (s *MemoryStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error

CreateSession stores a session. CreateSession 保存 session。

func (*MemoryStore) Prune

func (s *MemoryStore) Prune()

Prune removes expired sessions. Prune 清理过期 session。

func (*MemoryStore) RevokeSession

func (s *MemoryStore) RevokeSession(ctx context.Context, sessionID string) error

RevokeSession deletes a session. RevokeSession 删除 session。

func (*MemoryStore) RotateRefresh

func (s *MemoryStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)

RotateRefresh replaces the refresh state for a session. RotateRefresh 替换某个 session 的 refresh 状态。

func (*MemoryStore) Session

func (s *MemoryStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)

Session returns the session when still active. Session 返回仍然活跃的 session。

func (*MemoryStore) UserVersion

func (s *MemoryStore) UserVersion(ctx context.Context, userID string) (int64, error)

UserVersion returns the current version for userID. UserVersion 返回 userID 的当前版本。

type RedisOptions

type RedisOptions struct {
	Prefix       string
	WriteTimeout time.Duration
	ReadTimeout  time.Duration
}

RedisOptions configures NewRedisStore. RedisOptions 配置 NewRedisStore。

type RedisStore

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

RedisStore stores sessions in Redis. RedisStore 在 Redis 中保存 session。

func NewRedisStore

func NewRedisStore(client *redis.Client, opts RedisOptions) *RedisStore

NewRedisStore returns a Redis-backed SessionStore. NewRedisStore 返回 Redis 版 SessionStore。

func (*RedisStore) BumpUserVersion

func (s *RedisStore) BumpUserVersion(ctx context.Context, userID string) (int64, error)

BumpUserVersion invalidates all sessions for userID. BumpUserVersion 通过提升版本使 userID 的全部 session 失效。

func (*RedisStore) CreateSession

func (s *RedisStore) CreateSession(ctx context.Context, sessionID string, state SessionState) error

CreateSession stores a session. CreateSession 保存 session。

func (*RedisStore) RevokeSession

func (s *RedisStore) RevokeSession(ctx context.Context, sessionID string) error

RevokeSession deletes a session. RevokeSession 删除 session。

func (*RedisStore) RotateRefresh

func (s *RedisStore) RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)

RotateRefresh replaces the refresh state for a session. RotateRefresh 替换某个 session 的 refresh 状态。

func (*RedisStore) Session

func (s *RedisStore) Session(ctx context.Context, sessionID string) (SessionState, bool, error)

Session returns the session when still active. Session 返回仍然活跃的 session。

func (*RedisStore) UserVersion

func (s *RedisStore) UserVersion(ctx context.Context, userID string) (int64, error)

UserVersion returns the current version for userID. UserVersion 返回 userID 的当前版本。

type SessionState

type SessionState struct {
	UserID      string
	RefreshID   string
	ExpiresAt   time.Time
	SessionOnly bool
}

SessionState stores session state for refresh rotation and revocation. SessionState 保存 refresh 轮换与吊销所需的 session 状态。

type SessionStore

type SessionStore interface {
	UserVersion(ctx context.Context, userID string) (int64, error)
	BumpUserVersion(ctx context.Context, userID string) (int64, error)
	CreateSession(ctx context.Context, sessionID string, state SessionState) error
	Session(ctx context.Context, sessionID string) (SessionState, bool, error)
	RotateRefresh(ctx context.Context, sessionID, userID string, expectedVersion int64, oldRefreshID, newRefreshID string, exp time.Time) (bool, error)
	RevokeSession(ctx context.Context, sessionID string) error
}

SessionStore persists user versions and active sessions. Backend availability failures must be normalized to ErrStoreUnavailable. SessionStore 持久化用户版本与活跃 session。 后端可用性错误必须统一为 ErrStoreUnavailable。

Jump to

Keyboard shortcuts

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