server

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package server wires the hub, auth, limits and metrics packages into an http.Handler serving the two upgrade endpoints (/v1/agent, /v1/client) and /healthz. It is the only package that speaks WebSocket protocol directly — reading hellos, running the forwarding pump, broadcasting going_away on shutdown.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

func New

func New(cfg config.Config, h *hub.Hub, authz auth.Authorizer, ipLim *limits.IPLimiter, m *metrics.Metrics, log *slog.Logger) *Server

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns the mux serving /v1/agent, /v1/client, /healthz and /stats — exposed separately from Run so tests can drive it via httptest.Server without binding a real port.

func (*Server) Run

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

Run listens on cfg.Addr and blocks until ctx is cancelled, then performs a graceful shutdown bounded by cfg.ShutdownGrace.

func (*Server) Serve

func (s *Server) Serve(ctx context.Context, ln net.Listener) error

Serve runs the server on an already-open listener — split out from Run so tests can use a listener bound to an ephemeral port.

func (*Server) Shutdown

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

Shutdown announces going_away to every currently-open connection, waits (bounded by ctx) for their pumps to drain, then stops the HTTP listener.

This exists because net/http.Server.Shutdown explicitly does NOT wait for hijacked connections — and a WebSocket upgrade hijacks the underlying TCP connection — so without this, every open session would hang until its own ping-timeout on every deploy instead of getting a clean, fast reconnect signal (spec §8: close code 1001, retry with no backoff escalation).

Jump to

Keyboard shortcuts

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