session

package
v0.14.3 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

CRC: crc-SessionManager.md Spec: interfaces.md, protocol.md

Package session implements session management for the UI server. CRC: crc-Session.md, crc-SessionManager.md Spec: main.md (UI Server Architecture - Frontend Layer), interfaces.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GenerateSessionID

func GenerateSessionID() string

GenerateSessionID creates a unique session identifier.

Types

type Manager

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

Manager manages all sessions.

func NewManager

func NewManager(sessionTimeout time.Duration) *Manager

NewManager creates a new session manager.

func (*Manager) CleanupInactiveSessions

func (m *Manager) CleanupInactiveSessions() int

CleanupInactiveSessions removes sessions with no activity past the timeout.

func (*Manager) Count

func (m *Manager) Count() int

Count returns the number of sessions.

func (*Manager) CreateSession

func (m *Manager) CreateSession() (*Session, string, error)

CreateSession generates a new session ID and initializes the session. Returns the session and its vended ID (compact integer string for backend communication). Note: Variable 1 (app variable) is NOT created here. It's created by: - Lua main.lua calling session:createAppVariable() (Lua-only mode) - External backend via protocol (backend-only mode)

func (*Manager) DestroySession

func (m *Manager) DestroySession(id string) error

DestroySession cleans up a session and all its resources.

func (*Manager) Get

func (m *Manager) Get(id string) *Session

Get retrieves a session by ID. Returns nil if not found.

func (*Manager) GetAllSessions

func (m *Manager) GetAllSessions() []*Session

GetAllSessions returns all sessions.

func (*Manager) GetInternalID

func (m *Manager) GetInternalID(vendedID string) string

GetInternalID returns the internal session ID for a vended ID. Returns empty string if session not found.

func (*Manager) GetSession

func (m *Manager) GetSession(id string) (*Session, bool)

GetSession retrieves a session by ID.

func (*Manager) GetVendedID

func (m *Manager) GetVendedID(internalID string) string

GetVendedID returns the vended ID for an internal session ID. Returns empty string if session not found.

func (*Manager) RegisterURLPath

func (m *Manager) RegisterURLPath(sessionID, path string, variableID int64) error

RegisterURLPath associates a URL path with a presenter variable for a session.

func (*Manager) ResolveURLPath

func (m *Manager) ResolveURLPath(sessionID, path string) (int64, bool)

ResolveURLPath finds the presenter variable for a URL path in a session.

func (*Manager) SessionExists

func (m *Manager) SessionExists(id string) bool

SessionExists checks if a session ID is valid.

func (*Manager) SetOnSessionCreated

func (m *Manager) SetOnSessionCreated(callback SessionCreatedCallback)

SetOnSessionCreated sets a callback called when a session is created.

func (*Manager) SetOnSessionDestroyed

func (m *Manager) SetOnSessionDestroyed(callback SessionDestroyedCallback)

SetOnSessionDestroyed sets a callback called when a session is destroyed.

type Session

type Session struct {
	ID            string
	AppVariableID int64 // Variable 1 - root app variable
	// contains filtered or unexported fields
}

Session represents a single user session. Session is part of the frontend layer - it routes messages to backend. CRC: crc-Session.md

func NewSession

func NewSession(id string) *Session

NewSession creates a new session with the given ID.

func (*Session) AddConnection

func (s *Session) AddConnection(connectionID string)

AddConnection registers a new connection to this session.

func (*Session) GetAppVariableID

func (s *Session) GetAppVariableID() int64

GetAppVariableID returns the root variable ID.

func (*Session) GetBackend

func (s *Session) GetBackend() backend.Backend

GetBackend returns the backend instance for this session.

func (*Session) GetConnectionCount

func (s *Session) GetConnectionCount() int

GetConnectionCount returns the number of active connections.

func (*Session) GetConnections

func (s *Session) GetConnections() []string

GetConnections returns a copy of the connection IDs.

func (*Session) GetCreatedAt

func (s *Session) GetCreatedAt() time.Time

GetCreatedAt returns the session creation time.

func (*Session) GetID

func (s *Session) GetID() string

GetID returns the session ID.

func (*Session) GetLastActivity

func (s *Session) GetLastActivity() time.Time

GetLastActivity returns the last activity time.

func (*Session) IsActive

func (s *Session) IsActive() bool

IsActive checks if the session has any connections.

func (*Session) RemoveConnection

func (s *Session) RemoveConnection(connectionID string) bool

RemoveConnection unregisters a connection from this session. Calls backend.UnwatchAll to clean up watches for this connection. Returns true if this was the last frontend connection. CRC: crc-Session.md

func (*Session) SetAppVariableID

func (s *Session) SetAppVariableID(id int64)

SetAppVariableID sets the root variable ID.

func (*Session) SetBackend

func (s *Session) SetBackend(b backend.Backend)

SetBackend sets the backend instance for this session.

func (*Session) Touch

func (s *Session) Touch()

Touch updates the lastActivity timestamp.

type SessionCreatedCallback

type SessionCreatedCallback func(vendedID string, session *Session) error

SessionCreatedCallback is called when a new session is created. Receives the vended session ID (compact integer string) and the session object.

type SessionDestroyedCallback

type SessionDestroyedCallback func(vendedID string, session *Session)

SessionDestroyedCallback is called when a session is destroyed. Receives the vended session ID (compact integer string) and the session object.

Jump to

Keyboard shortcuts

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