api

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2026 License: MIT Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EventBroadcaster

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

EventBroadcaster manages SSE client subscriptions and broadcasts events.

func NewEventBroadcaster

func NewEventBroadcaster() *EventBroadcaster

NewEventBroadcaster creates a new broadcaster.

func (*EventBroadcaster) Broadcast

func (b *EventBroadcaster) Broadcast(event GatewayEvent)

Broadcast sends a GatewayEvent to all connected SSE clients.

func (*EventBroadcaster) Subscribe

func (b *EventBroadcaster) Subscribe() chan string

Subscribe adds a new listener channel and returns it. The caller must call Unsubscribe when done.

func (*EventBroadcaster) Unsubscribe

func (b *EventBroadcaster) Unsubscribe(ch chan string)

Unsubscribe removes a listener channel and closes it.

type GatewayEvent

type GatewayEvent struct {
	Status string `json:"gateway_status"` // "running", "starting", "stopped", "error"
	PID    int    `json:"pid,omitempty"`
}

GatewayEvent represents a state change event for the gateway process.

type Handler

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

Handler serves HTTP API requests.

func NewHandler

func NewHandler(configPath string) *Handler

NewHandler creates an instance of the API handler.

func (*Handler) RegisterRoutes

func (h *Handler) RegisterRoutes(mux *http.ServeMux)

RegisterRoutes binds all API endpoint handlers to the ServeMux.

func (*Handler) SetServerOptions

func (h *Handler) SetServerOptions(port int, public bool, allowedCIDRs []string)

SetServerOptions stores current backend listen options for fallback behavior.

func (*Handler) TryAutoStartGateway

func (h *Handler) TryAutoStartGateway()

TryAutoStartGateway checks whether gateway start preconditions are met and starts it when possible. Intended to be called by the backend at startup.

type LogBuffer

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

LogBuffer is a thread-safe ring buffer that stores the most recent N log lines. It supports incremental reads via LinesSince and tracks a runID that increments on each Reset (used to detect gateway restarts).

func NewLogBuffer

func NewLogBuffer(capacity int) *LogBuffer

NewLogBuffer creates a LogBuffer with the given capacity.

func (*LogBuffer) Append

func (b *LogBuffer) Append(line string)

Append adds a line to the buffer. If the buffer is full, the oldest line is evicted.

func (*LogBuffer) LinesSince

func (b *LogBuffer) LinesSince(offset int) (lines []string, total int, runID int)

LinesSince returns lines appended after the given offset, the current total count, and the runID. If offset >= total, no lines are returned. If offset is too old (evicted), all buffered lines are returned.

func (*LogBuffer) Reset

func (b *LogBuffer) Reset()

Reset clears the buffer and increments the runID. Call this when starting a new gateway process.

func (*LogBuffer) RunID

func (b *LogBuffer) RunID() int

RunID returns the current run identifier.

Jump to

Keyboard shortcuts

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