web

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package web provides an embedded HTTP server for the initech web companion. It serves a single-page application from embedded static files and exposes a JSON API for pane information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PaneInfo

type PaneInfo struct {
	Name     string `json:"name"`
	Host     string `json:"host,omitempty"`
	Activity string `json:"activity"`
	Alive    bool   `json:"alive"`
	Visible  bool   `json:"visible"`
}

PaneInfo describes a single managed pane. Mirrors tui.PaneInfo so the web package does not import tui directly.

type PaneLister

type PaneLister interface {
	AllPanes() ([]PaneInfo, bool)
}

PaneLister returns the current set of panes. The bool is false if the underlying system is shutting down and the data is unavailable.

type PaneSubscriber

type PaneSubscriber interface {
	// SubscribePane registers a subscriber for the named pane's PTY output.
	// Returns a channel of byte slices and true if the pane exists, or
	// nil and false if the pane is not found.
	SubscribePane(paneName, subscriberID string) (chan []byte, bool)

	// UnsubscribePane removes a subscriber. Safe to call if the pane or
	// subscriber does not exist.
	UnsubscribePane(paneName, subscriberID string)
}

PaneSubscriber provides fan-out subscription to a pane's PTY byte stream. The returned channel receives copies of all bytes read from the pane's PTY. Callers must call UnsubscribePane when done.

type Server

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

Server is an HTTP server that serves the SPA and pane API.

func NewServer

func NewServer(port int, lister PaneLister, subscriber PaneSubscriber, logger *slog.Logger) *Server

NewServer creates a Server bound to 0.0.0.0 on the given port, accessible from other machines on the network. The operator explicitly enables this with --web-port, so we bind all interfaces by default. If port is 0, the OS assigns a free port. The subscriber parameter is optional; if nil, the /ws/pane/{name} endpoint returns 501.

func (*Server) Addr

func (s *Server) Addr() string

Addr returns the address the server is bound to. Only meaningful after Start has been called (and the listener is active).

func (*Server) Shutdown

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

Shutdown gracefully stops the server.

func (*Server) Start

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

Start begins listening and serving. It blocks until the server is shut down or a fatal listen error occurs. The returned error is nil on clean shutdown (via Shutdown) and non-nil on listen failure.

Jump to

Keyboard shortcuts

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