session

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: Apache-2.0 Imports: 6 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")
	ErrSessionInvalid  = errors.New("session invalid")
)

Domain errors

Functions

This section is empty.

Types

type Repository

type Repository interface {
	// Create creates a new session
	Create(ctx context.Context, session *Session) error

	// Get retrieves a session by ID
	Get(ctx context.Context, sessionID string) (*Session, error)

	// Update updates session last seen time
	Update(ctx context.Context, session *Session) error

	// Delete deletes a session
	Delete(ctx context.Context, sessionID string) error

	// DeleteByUserID deletes all sessions for a user
	DeleteByUserID(ctx context.Context, userID string) error

	// DeleteExpired deletes all expired sessions
	DeleteExpired(ctx context.Context) error
}

Repository defines the interface for session persistence.

Purpose: Abstraction for managing persistent session storage. Domain: Session

type Service

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

Service provides session management business logic.

Purpose: Implementation of session lifecycle and validation rules. Domain: Session

func NewService

func NewService(repo Repository, lifetime, idleTimeout time.Duration) *Service

NewService creates a new session service.

Purpose: Constructor for the session management service. Domain: Session Audited: No Errors: None

func (*Service) CleanupExpired

func (s *Service) CleanupExpired(ctx context.Context) error

CleanupExpired removes all expired sessions

func (*Service) Create

func (s *Service) Create(ctx context.Context, tenantID *string, userID, ipAddress, userAgent, namespace string) (*Session, error)

Create creates a new session for a user.

Purpose: Initializes a new persistent session after successful authentication. Domain: Session Audited: No Errors: System errors

func (*Service) Destroy

func (s *Service) Destroy(ctx context.Context, sessionID string) error

Destroy destroys a session

func (*Service) DestroyAllForUser

func (s *Service) DestroyAllForUser(ctx context.Context, userID string) error

DestroyAllForUser destroys all sessions for a user

func (*Service) Get

func (s *Service) Get(ctx context.Context, sessionID string) (*Session, error)

Get retrieves and validates a session

func (*Service) Refresh

func (s *Service) Refresh(ctx context.Context, sessionID string) error

Refresh refreshes a session's last seen time.

Purpose: Keeps a session alive by updating its activity timestamp. Domain: Session Audited: No Errors: ErrSessionNotFound, ErrSessionExpired

type Session

type Session struct {
	ID         string
	TenantID   *string
	UserID     string
	IPAddress  string
	UserAgent  string
	ExpiresAt  time.Time
	CreatedAt  time.Time
	LastSeenAt time.Time
	Namespace  string // "auth" or "admin"
}

Session represents a user session.

Purpose: Server-side record of an authenticated user's persistence. Domain: Session Invariants: ID must be a cryptographically secure token. UserID must exist.

func (*Session) IsExpired

func (s *Session) IsExpired() bool

IsExpired checks if the session has expired

func (*Session) IsIdle

func (s *Session) IsIdle(idleTimeout time.Duration) bool

IsIdle checks if the session has been idle for too long

Jump to

Keyboard shortcuts

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