server

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 26, 2025 License: MIT Imports: 29 Imported by: 0

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

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

func (h *HTTPEndpoint) HandleProtocolCommand(msg *protocol.Message) (*protocol.Response, error)

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) Poll

func (m *PendingQueueManager) Poll(connectionID string, wait time.Duration) []*protocol.Message

Poll implements protocol.PendingQueuer interface.

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.

func (*PendingResponseQueue) Poll

Poll returns pending messages, optionally waiting for availability. If wait is 0, returns immediately. Otherwise waits up to the duration.

type Server

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

Server is the main UI server. CRC: crc-Server.md

func New

func New(cfg *config.Config) *Server

New creates a new server with the given configuration.

func (*Server) AfterBatch

func (s *Server) AfterBatch(internalSessionID string)

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

func (s *Server) CreateLuaBackendForSession(vendedID string, sess *session.Session) error

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

func (s *Server) DestroyLuaBackendForSession(vendedID string, sess *session.Session)

DestroyLuaBackendForSession destroys a session's LuaBackend. vendedID is the compact integer ID (e.g., "1", "2") for backend communication.

func (*Server) GetHandler

func (s *Server) GetHandler() *protocol.Handler

GetHandler returns the protocol handler.

func (*Server) GetLuaRuntime

func (s *Server) GetLuaRuntime() *lua.Runtime

GetLuaRuntime returns the Lua runtime (for testing/advanced use).

func (*Server) GetSessions

func (s *Server) GetSessions() *session.Manager

GetSessions returns the session manager.

func (*Server) GetStore

func (s *Server) GetStore() *variable.Store

GetStore returns the variable store.

func (*Server) SetSiteFS

func (s *Server) SetSiteFS(siteFS fs.FS)

SetSiteFS sets a custom filesystem for serving static files.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully shuts down the server.

func (*Server) Start

func (s *Server) Start() error

Start starts the server.

func (*Server) StartCleanupWorker

func (s *Server) StartCleanupWorker(interval time.Duration)

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.

Jump to

Keyboard shortcuts

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