api

package
v1.4.2 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package api provides WebSocket hub and client types for real-time dashboard communication.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

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

Client is a middleman between the websocket connection and the hub.

func NewClient

func NewClient(hub *Hub, conn *websocket.Conn) *Client

NewClient creates a new WebSocket client.

func (*Client) Start

func (c *Client) Start()

Start starts the client's read and write pumps.

type Gateway

type Gateway interface {
	Config() bastion.Config
	RouteManager() bastion.RouteRegistry
	HealthMonitor() *health.Monitor
	Snapshot() *bastion.GatewayStats
	AccessLog() *observability.AccessLogger
	Discovery() *bastion.ServiceDiscovery
	Logger() forge.Logger
	Hub() bastion.WSBroadcaster
}

Gateway provides the admin API with access to gateway components.

type Handlers

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

Handlers provides REST API handlers for the gateway admin.

func NewHandlers

func NewHandlers(gw Gateway, hub *Hub, svc *admin.Service) *Handlers

NewHandlers creates new admin API handlers.

func (*Handlers) HandleCreateRoute

func (h *Handlers) HandleCreateRoute(ctx forge.Context) error

HandleCreateRoute creates a new manual route.

func (*Handlers) HandleDebugDiscovery

func (h *Handlers) HandleDebugDiscovery(ctx forge.Context) error

HandleDebugDiscovery performs a one-shot discovery probe and returns raw results for diagnosing mDNS/service discovery issues.

func (*Handlers) HandleDeleteRoute

func (h *Handlers) HandleDeleteRoute(ctx forge.Context) error

HandleDeleteRoute deletes a manual route.

func (*Handlers) HandleDeregisterService

func (h *Handlers) HandleDeregisterService(ctx forge.Context) error

HandleDeregisterService removes a pushed service and its routes.

func (*Handlers) HandleDisableRoute

func (h *Handlers) HandleDisableRoute(ctx forge.Context) error

HandleDisableRoute disables a route.

func (*Handlers) HandleEnableRoute

func (h *Handlers) HandleEnableRoute(ctx forge.Context) error

HandleEnableRoute enables a route.

func (*Handlers) HandleFARPDeregister

func (h *Handlers) HandleFARPDeregister(ctx forge.Context) error

HandleFARPDeregister handles FARP v1 deregistration. DELETE /_farp/v1/deregister/:id

func (*Handlers) HandleFARPHeartbeat

func (h *Handlers) HandleFARPHeartbeat(ctx forge.Context) error

HandleFARPHeartbeat handles FARP v1 heartbeat protocol. PUT /_farp/v1/heartbeat/:id

Returns the gateway's known routes_checksum so the service SDK can detect mismatches and trigger re-registration for reconciliation.

func (*Handlers) HandleFARPRegister

func (h *Handlers) HandleFARPRegister(ctx forge.Context) error

HandleFARPRegister handles the FARP v1 push registration protocol. POST /_farp/v1/register — accepts {instance: {...}, manifest?: {...}} The gateway fetches the full manifest from the service's /_farp/manifest endpoint if not included in the payload.

func (*Handlers) HandleGetConfig

func (h *Handlers) HandleGetConfig(ctx forge.Context) error

HandleGetConfig returns the current gateway configuration.

func (*Handlers) HandleGetRoute

func (h *Handlers) HandleGetRoute(ctx forge.Context) error

HandleGetRoute returns a single route by ID.

func (*Handlers) HandleGetRouteStats

func (h *Handlers) HandleGetRouteStats(ctx forge.Context) error

HandleGetRouteStats returns per-route statistics.

func (*Handlers) HandleGetStats

func (h *Handlers) HandleGetStats(ctx forge.Context) error

HandleGetStats returns aggregated gateway statistics.

func (*Handlers) HandleListDiscoveredServices

func (h *Handlers) HandleListDiscoveredServices(ctx forge.Context) error

HandleListDiscoveredServices returns all discovered services.

func (*Handlers) HandleListRoutes

func (h *Handlers) HandleListRoutes(ctx forge.Context) error

HandleListRoutes returns all routes.

func (*Handlers) HandleListUpstreams

func (h *Handlers) HandleListUpstreams(ctx forge.Context) error

HandleListUpstreams returns all targets with health status.

func (*Handlers) HandleRefreshDiscovery

func (h *Handlers) HandleRefreshDiscovery(ctx forge.Context) error

HandleRefreshDiscovery forces a FARP re-scan.

func (*Handlers) HandleRegisterService

func (h *Handlers) HandleRegisterService(ctx forge.Context) error

HandleRegisterService accepts a service registration push. Services POST their info to this endpoint so the gateway can build routes from their FARP manifest.

func (*Handlers) HandleUpdateRoute

func (h *Handlers) HandleUpdateRoute(ctx forge.Context) error

HandleUpdateRoute updates an existing route.

func (*Handlers) HandleWebSocket

func (h *Handlers) HandleWebSocket(ctx forge.Context) error

HandleWebSocket handles the dashboard WebSocket connection.

type Hub

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

Hub maintains the set of active WebSocket clients.

func NewHub

func NewHub(logger forge.Logger) *Hub

NewHub creates a new WebSocket hub.

func (*Hub) Broadcast

func (h *Hub) Broadcast(data any) error

Broadcast sends a message to all connected clients.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) Run

func (h *Hub) Run()

Run starts the hub's main loop.

type WSMessage

type WSMessage struct {
	Type      string    `json:"type"`
	Timestamp time.Time `json:"timestamp"`
	Data      any       `json:"data"`
}

WSMessage represents a WebSocket message.

func NewWSMessage

func NewWSMessage(msgType string, data any) WSMessage

NewWSMessage creates a new WebSocket message.

Jump to

Keyboard shortcuts

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