sse

package
v1.0.430 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 2 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 sse is the Server-Sent-Events client hub: registration under a connection cap, fan-out broadcast with slow-client eviction, and the hub-level observability counters. Extracted from package main's events.go per ADR-0002 as a pure stdlib leaf. The dashboard broadcaster (which assembles the payload from main's stats globals), the /api/events handler (auth, framing, mid-stream revalidation), and the Prometheus exposition stay in package main; main reads the counters through the accessors.

Index

Constants

View Source
const DefaultMaxClients = 256

DefaultMaxClients is the default connection cap (see Hub.SetMaxClients).

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

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

Hub manages SSE client channels for a live event stream. All methods are safe for concurrent use.

func NewHub

func NewHub() *Hub

NewHub returns an empty hub with the default connection cap.

func (*Hub) AddRejected

func (h *Hub) AddRejected()

AddRejected increments the rejected-connection counter. Called by the stream handler when Register reports the hub is full (the handler owns the HTTP 503, so it owns the count).

func (*Hub) Broadcast

func (h *Hub) Broadcast(msg []byte)

Broadcast sends msg to every registered client. Clients whose channel is full are closed and removed (B21: prevents stale connections from accumulating and missing state updates) and counted in Evicted.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of connected clients.

func (*Hub) ClientsForTest

func (h *Hub) ClientsForTest() []chan []byte

ClientsForTest returns the currently registered channels. Test support for integration tests that diff the client set to find the channel a handler registered (replaces the pre-extraction whitebox map iteration).

func (*Hub) EvictForTest

func (h *Hub) EvictForTest(ch chan []byte)

EvictForTest closes and removes ch, mirroring Broadcast's B21 slow-client eviction (without touching the evicted counter). Test support for the handler test that simulates an eviction mid-stream.

func (*Hub) Evicted

func (h *Hub) Evicted() int64

Evicted returns the cumulative count of slow clients evicted by Broadcast.

func (*Hub) MaxClients

func (h *Hub) MaxClients() int64

MaxClients returns the current connection cap (0 = uncapped).

func (*Hub) Register

func (h *Hub) Register(ch chan []byte) bool

Register adds the client channel to the hub. It reports false — without registering — when the hub is already at the connection cap.

func (*Hub) Rejected

func (h *Hub) Rejected() int64

Rejected returns the cumulative count of connections rejected at the cap.

func (*Hub) SetMaxClients

func (h *Hub) SetMaxClients(n int64)

SetMaxClients sets the connection cap (0 disables it). Existing connections are not evicted when the cap is lowered.

func (*Hub) Unregister

func (h *Hub) Unregister(ch chan []byte)

Unregister removes the client channel from the hub.

Jump to

Keyboard shortcuts

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