Documentation
¶
Index ¶
- Variables
- type Repository
- type Service
- func (s *Service) CleanupExpired(ctx context.Context) error
- func (s *Service) Create(ctx context.Context, tenantID *string, ...) (*Session, error)
- func (s *Service) Destroy(ctx context.Context, sessionID string) error
- func (s *Service) DestroyAllForUser(ctx context.Context, userID string) error
- func (s *Service) Get(ctx context.Context, sessionID string) (*Session, error)
- func (s *Service) Refresh(ctx context.Context, sessionID string) error
- type Session
Constants ¶
This section is empty.
Variables ¶
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 ¶
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) DestroyAllForUser ¶
DestroyAllForUser destroys all sessions for a user
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.