websocket

package
v0.1.28 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package websocket serves EVE-KILL's live event streams.

Workers publish small envelopes to Redis channels prefixed with ws:. This server subscribes once and fans each event out to browser connections on /ws/*. Killmail streams are topic-routed; comments, status and announcements are broadcast to every connection on their endpoint.

Redis pub/sub is intentionally best-effort. The durable data is already in Postgres, and the feed API has its own sequence-backed recovery path. A relay outage may miss a live notification but must never retry killmail processing.

Index

Constants

View Source
const BasePath = "/ws"

Variables

This section is empty.

Functions

This section is empty.

Types

type Endpoint

type Endpoint struct {
	Name         string
	Path         string
	Channel      string
	TopicRouting bool
}

Endpoint is one public WebSocket stream and its Redis pub/sub channel.

Paths are deliberately relative to BasePath. The browser-facing contract is /ws/<path>; keeping the prefix out of every definition prevents a future route move from silently changing the channel or the frame's channel field.

type EndpointStats

type EndpointStats struct {
	Connections   int            `json:"connections"`
	Subscriptions map[string]int `json:"subscriptions"`
}

type Server

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

Server owns the Redis subscription and every connected WebSocket.

Start and Close are idempotent. A Server may be constructed before Caddy is started, but Start should be called before the handler becomes reachable so the Redis subscription is already attempting to connect.

func New

func New(redisClient *redis.Client, log zerolog.Logger) *Server

New builds a relay over the coordination Redis instance.

func (*Server) Close

func (s *Server) Close()

Close stops the subscription and closes active clients.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves only the /ws contract.

There is deliberately no /ws/health or /ws/stats. Process liveness already lives at /health, while operational telemetry is available through Snapshot for later publication into the shared Redis telemetry stream.

func (*Server) Snapshot

func (s *Server) Snapshot() Stats

Snapshot reports current connection and subscription counts.

func (*Server) Start

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

Start begins the Redis subscription and binds its lifetime to ctx.

type Stats

type Stats struct {
	Status      string                   `json:"status"`
	Uptime      int64                    `json:"uptime"`
	Timestamp   string                   `json:"timestamp"`
	Connections int                      `json:"connections"`
	Redis       bool                     `json:"redis"`
	Channels    []string                 `json:"channels"`
	Endpoints   map[string]EndpointStats `json:"endpoints"`
}

Stats is an internal operational snapshot.

It is intentionally not mounted as a public HTTP endpoint. A later telemetry publisher can put this exact value in Redis alongside Caddy, database and API snapshots for the status page and admin tooling.

Jump to

Keyboard shortcuts

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