Versions in this module Expand all Collapse all v0 v0.7.0 May 10, 2026 Changes in this version + var ErrInvalidSessionID = errors.New("invalid session ID") + var ErrSessionExpired = errors.New("session expired") + var ErrSessionInvalid = errors.New("session has been invalidated") + var ErrSessionNotFound = errors.New("session not found") + var ErrStorageFailure = errors.New("session storage failure") + type Config struct + CleanupInterval time.Duration + MaxSessionsPerUser int + SessionTTL time.Duration + func DefaultConfig() Config + type Manager struct + func NewManager(store SessionStore, opts ...ManagerOption) *Manager + func (m *Manager) Close() error + func (m *Manager) CreateSession(ctx context.Context, userID string, opts ...SessionOption) (*Session, error) + func (m *Manager) GetSession(ctx context.Context, sessionID string) (*Session, error) + func (m *Manager) InvalidateAllSessions(ctx context.Context, userID string) (int, error) + func (m *Manager) InvalidateDeviceSessions(ctx context.Context, userID, deviceID string) (int, error) + func (m *Manager) InvalidateOtherSessions(ctx context.Context, userID, currentSessionID string) (int, error) + func (m *Manager) InvalidateSession(ctx context.Context, sessionID string) error + func (m *Manager) ListSessions(ctx context.Context, userID string) ([]*Session, error) + func (m *Manager) RefreshSession(ctx context.Context, sessionID string) error + func (m *Manager) ValidateSession(ctx context.Context, sessionID string) (*Session, error) + type ManagerOption func(*Manager) + func WithConfig(cfg Config) ManagerOption + func WithMaxSessionsPerUser(max int) ManagerOption + func WithSessionTTL(ttl time.Duration) ManagerOption + type MemoryStore struct + func NewMemoryStore() *MemoryStore + func (m *MemoryStore) Close() error + func (m *MemoryStore) Count() int + func (m *MemoryStore) Create(ctx context.Context, session *Session) error + func (m *MemoryStore) Delete(ctx context.Context, sessionID string) error + func (m *MemoryStore) DeleteByDevice(ctx context.Context, userID, deviceID string) (int, error) + func (m *MemoryStore) DeleteByUser(ctx context.Context, userID string) (int, error) + func (m *MemoryStore) DeleteExpired(ctx context.Context) (int, error) + func (m *MemoryStore) Get(ctx context.Context, sessionID string) (*Session, error) + func (m *MemoryStore) ListByUser(ctx context.Context, userID string) ([]*Session, error) + func (m *MemoryStore) Update(ctx context.Context, session *Session) error + type RedisStore struct + func NewRedisStore(client redis.UniversalClient, opts ...RedisStoreOption) *RedisStore + func (r *RedisStore) Close() error + func (r *RedisStore) Create(ctx context.Context, session *Session) error + func (r *RedisStore) Delete(ctx context.Context, sessionID string) error + func (r *RedisStore) DeleteByDevice(ctx context.Context, userID, deviceID string) (int, error) + func (r *RedisStore) DeleteByUser(ctx context.Context, userID string) (int, error) + func (r *RedisStore) DeleteExpired(ctx context.Context) (int, error) + func (r *RedisStore) Get(ctx context.Context, sessionID string) (*Session, error) + func (r *RedisStore) ListByUser(ctx context.Context, userID string) ([]*Session, error) + func (r *RedisStore) Update(ctx context.Context, session *Session) error + type RedisStoreOption func(*RedisStore) + func WithKeyPrefix(prefix string) RedisStoreOption + type Session struct + CreatedAt time.Time + DeviceID string + DeviceInfo string + ExpiresAt time.Time + ID string + IPAddress string + LastActiveAt time.Time + Metadata map[string]string + UserID string + func (s *Session) IsExpired() bool + type SessionOption func(*Session) + func WithDeviceID(deviceID string) SessionOption + func WithDeviceInfo(info string) SessionOption + func WithIPAddress(ip string) SessionOption + func WithMetadata(key, value string) SessionOption + func WithTTL(ttl time.Duration) SessionOption + type SessionStore interface + Close func() error + Create func(ctx context.Context, session *Session) error + Delete func(ctx context.Context, sessionID string) error + DeleteByDevice func(ctx context.Context, userID, deviceID string) (int, error) + DeleteByUser func(ctx context.Context, userID string) (int, error) + DeleteExpired func(ctx context.Context) (int, error) + Get func(ctx context.Context, sessionID string) (*Session, error) + ListByUser func(ctx context.Context, userID string) ([]*Session, error) + Update func(ctx context.Context, session *Session) error