Documentation
¶
Overview ¶
CRC: crc-BackendSocket.md, crc-ProtocolDetector.md, crc-PacketProtocol.md Spec: deployment.md
CRC: crc-HTTPEndpoint.md Spec: interfaces.md, deployment.md
CRC: crc-PendingResponseQueue.md Spec: deployment.md
CRC: seq-server-startup.md Spec: deployment.md
Package server implements the UI server communication layer. CRC: crc-WebSocketEndpoint.md Spec: interfaces.md
Index ¶
- func DefaultSocketPath() string
- type AfterBatchCallback
- type BackendSocket
- type HTTPEndpoint
- type PendingQueueManager
- func (m *PendingQueueManager) Enqueue(connectionID string, msg *protocol.Message)
- func (m *PendingQueueManager) EnqueueTo(msg *protocol.Message, connectionIDs []string)
- func (m *PendingQueueManager) EnqueueToAll(msg *protocol.Message)
- func (m *PendingQueueManager) GetQueue(connectionID string) *PendingResponseQueue
- func (m *PendingQueueManager) Poll(connectionID string, wait time.Duration) []*protocol.Message
- func (m *PendingQueueManager) RemoveQueue(connectionID string)
- type PendingResponseQueue
- type Server
- func (s *Server) AfterBatch(internalSessionID string)
- func (s *Server) CreateLuaBackendForSession(vendedID string, sess *session.Session) error
- func (s *Server) DestroyLuaBackendForSession(vendedID string, sess *session.Session)
- func (s *Server) GetHandler() *protocol.Handler
- func (s *Server) GetLuaRuntime() *lua.Runtime
- func (s *Server) GetSessions() *session.Manager
- func (s *Server) GetStore() *variable.Store
- func (s *Server) SetSiteFS(siteFS fs.FS)
- func (s *Server) Shutdown(ctx context.Context) error
- func (s *Server) Start() error
- func (s *Server) StartCleanupWorker(interval time.Duration)
- type WebSocketEndpoint
- func (ws *WebSocketEndpoint) Broadcast(sessionID string, msg *protocol.Message) error
- func (ws *WebSocketEndpoint) GenerateReconnectToken(sessionID string) string
- func (ws *WebSocketEndpoint) GetSessionID(connectionID string) (string, bool)
- func (ws *WebSocketEndpoint) GetSessionIDForConnection(connectionID string) string
- func (ws *WebSocketEndpoint) HandleWebSocket(w http.ResponseWriter, r *http.Request, sessionID string)
- func (ws *WebSocketEndpoint) IsConnected(connectionID string) bool
- func (ws *WebSocketEndpoint) IsSessionReconnectable(sessionID string) bool
- func (ws *WebSocketEndpoint) Log(level int, format string, args ...interface{})
- func (ws *WebSocketEndpoint) Send(connectionID string, msg *protocol.Message) error
- func (ws *WebSocketEndpoint) SetAfterBatch(callback AfterBatchCallback)
- func (ws *WebSocketEndpoint) ValidateReconnectToken(sessionID, token string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultSocketPath ¶
func DefaultSocketPath() string
DefaultSocketPath returns the platform-specific default socket path.
Types ¶
type AfterBatchCallback ¶
type AfterBatchCallback func(sessionID string)
AfterBatchCallback is called after processing a message batch to trigger change detection.
type BackendSocket ¶
type BackendSocket struct {
// contains filtered or unexported fields
}
BackendSocket handles the backend API socket.
func NewBackendSocket ¶
func NewBackendSocket(cfg *config.Config, socketPath string, handler *protocol.Handler, httpHandler *HTTPEndpoint) *BackendSocket
NewBackendSocket creates a new backend socket handler.
func (*BackendSocket) Broadcast ¶
func (bs *BackendSocket) Broadcast(msg *protocol.Message) error
Broadcast sends a message to all connected backends.
func (*BackendSocket) Close ¶
func (bs *BackendSocket) Close() error
Close closes the socket and all connections.
func (*BackendSocket) GetSocketPath ¶
func (bs *BackendSocket) GetSocketPath() string
GetSocketPath returns the socket path.
func (*BackendSocket) Listen ¶
func (bs *BackendSocket) Listen() error
Listen starts listening on the backend socket.
func (*BackendSocket) Log ¶
func (bs *BackendSocket) Log(level int, format string, args ...interface{})
Log logs a message via the config.
type HTTPEndpoint ¶
type HTTPEndpoint struct {
// contains filtered or unexported fields
}
HTTPEndpoint handles HTTP requests.
func NewHTTPEndpoint ¶
func NewHTTPEndpoint(sessions *session.Manager, handler *protocol.Handler, wsEndpoint *WebSocketEndpoint) *HTTPEndpoint
NewHTTPEndpoint creates a new HTTP endpoint.
func (*HTTPEndpoint) HandleProtocolCommand ¶
HandleProtocolCommand processes CLI protocol commands.
func (*HTTPEndpoint) ServeHTTP ¶
func (h *HTTPEndpoint) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler.
func (*HTTPEndpoint) SetEmbeddedSite ¶
func (h *HTTPEndpoint) SetEmbeddedSite(site fs.FS)
SetEmbeddedSite sets the embedded site filesystem.
func (*HTTPEndpoint) SetStaticDir ¶
func (h *HTTPEndpoint) SetStaticDir(dir string)
SetStaticDir sets a custom directory for static files.
type PendingQueueManager ¶
type PendingQueueManager struct {
// contains filtered or unexported fields
}
PendingQueueManager manages pending queues per connection.
func NewPendingQueueManager ¶
func NewPendingQueueManager() *PendingQueueManager
NewPendingQueueManager creates a new pending queue manager.
func (*PendingQueueManager) Enqueue ¶
func (m *PendingQueueManager) Enqueue(connectionID string, msg *protocol.Message)
Enqueue implements protocol.PendingQueuer interface.
func (*PendingQueueManager) EnqueueTo ¶
func (m *PendingQueueManager) EnqueueTo(msg *protocol.Message, connectionIDs []string)
EnqueueTo enqueues a message to specific connections.
func (*PendingQueueManager) EnqueueToAll ¶
func (m *PendingQueueManager) EnqueueToAll(msg *protocol.Message)
EnqueueToAll enqueues a message to all queues.
func (*PendingQueueManager) GetQueue ¶
func (m *PendingQueueManager) GetQueue(connectionID string) *PendingResponseQueue
GetQueue returns the queue for a connection, creating if needed.
func (*PendingQueueManager) RemoveQueue ¶
func (m *PendingQueueManager) RemoveQueue(connectionID string)
RemoveQueue removes a connection's queue.
type PendingResponseQueue ¶
type PendingResponseQueue struct {
// contains filtered or unexported fields
}
PendingResponseQueue accumulates push messages for polling clients.
func NewPendingResponseQueue ¶
func NewPendingResponseQueue() *PendingResponseQueue
NewPendingResponseQueue creates a new pending response queue.
func (*PendingResponseQueue) Drain ¶
func (q *PendingResponseQueue) Drain() []*protocol.Message
Drain returns all pending messages and clears the queue.
func (*PendingResponseQueue) Enqueue ¶
func (q *PendingResponseQueue) Enqueue(msg *protocol.Message)
Enqueue adds a message to the pending queue. Valid message types: update, error, destroy
func (*PendingResponseQueue) IsEmpty ¶
func (q *PendingResponseQueue) IsEmpty() bool
IsEmpty checks if the queue has pending messages.
func (*PendingResponseQueue) Len ¶
func (q *PendingResponseQueue) Len() int
Len returns the number of pending messages.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is the main UI server. CRC: crc-Server.md
func (*Server) AfterBatch ¶
AfterBatch triggers Lua change detection after processing a message batch. internalSessionID is the full UUID session ID (used in URLs/WebSocket bindings). This method looks up the vended ID and calls the Lua runtime's AfterBatch, then sends any detected changes to watching frontends. CRC: crc-Server.md Sequence: seq-relay-message.md, seq-backend-refresh.md
func (*Server) CreateLuaBackendForSession ¶
CreateLuaBackendForSession creates a LuaBackend for a new session. vendedID is the compact integer ID (e.g., "1", "2") for backend communication. The backend is attached to the session for per-session watch management. CRC: crc-LuaBackend.md Sequence: seq-session-create-backend.md
func (*Server) DestroyLuaBackendForSession ¶
DestroyLuaBackendForSession destroys a session's LuaBackend. vendedID is the compact integer ID (e.g., "1", "2") for backend communication.
func (*Server) GetHandler ¶
GetHandler returns the protocol handler.
func (*Server) GetLuaRuntime ¶
GetLuaRuntime returns the Lua runtime (for testing/advanced use).
func (*Server) GetSessions ¶
GetSessions returns the session manager.
func (*Server) StartCleanupWorker ¶
StartCleanupWorker starts a background worker to clean up inactive sessions.
type WebSocketEndpoint ¶
type WebSocketEndpoint struct {
// contains filtered or unexported fields
}
WebSocketEndpoint handles WebSocket connections.
func NewWebSocketEndpoint ¶
func NewWebSocketEndpoint(cfg *config.Config, sessions *session.Manager, handler *protocol.Handler) *WebSocketEndpoint
NewWebSocketEndpoint creates a new WebSocket endpoint.
func (*WebSocketEndpoint) Broadcast ¶
func (ws *WebSocketEndpoint) Broadcast(sessionID string, msg *protocol.Message) error
Broadcast sends a message to all connections in a session.
func (*WebSocketEndpoint) GenerateReconnectToken ¶
func (ws *WebSocketEndpoint) GenerateReconnectToken(sessionID string) string
GenerateReconnectToken creates a token for validating reconnection.
func (*WebSocketEndpoint) GetSessionID ¶
func (ws *WebSocketEndpoint) GetSessionID(connectionID string) (string, bool)
GetSessionID returns the session ID for a connection.
func (*WebSocketEndpoint) GetSessionIDForConnection ¶
func (ws *WebSocketEndpoint) GetSessionIDForConnection(connectionID string) string
GetSessionIDForConnection returns the session ID for a connection. Returns empty string if connection is not found.
func (*WebSocketEndpoint) HandleWebSocket ¶
func (ws *WebSocketEndpoint) HandleWebSocket(w http.ResponseWriter, r *http.Request, sessionID string)
HandleWebSocket handles incoming WebSocket connections.
func (*WebSocketEndpoint) IsConnected ¶
func (ws *WebSocketEndpoint) IsConnected(connectionID string) bool
IsConnected checks if a connection is active.
func (*WebSocketEndpoint) IsSessionReconnectable ¶
func (ws *WebSocketEndpoint) IsSessionReconnectable(sessionID string) bool
IsSessionReconnectable checks if a session can be rejoined. A session can be rejoined if it exists and hasn't timed out.
func (*WebSocketEndpoint) Log ¶
func (ws *WebSocketEndpoint) Log(level int, format string, args ...interface{})
Log logs a message via the config.
func (*WebSocketEndpoint) Send ¶
func (ws *WebSocketEndpoint) Send(connectionID string, msg *protocol.Message) error
Send sends a message to a specific connection.
func (*WebSocketEndpoint) SetAfterBatch ¶
func (ws *WebSocketEndpoint) SetAfterBatch(callback AfterBatchCallback)
SetAfterBatch sets the callback for change detection after message processing.
func (*WebSocketEndpoint) ValidateReconnectToken ¶
func (ws *WebSocketEndpoint) ValidateReconnectToken(sessionID, token string) bool
ValidateReconnectToken validates a reconnection token.