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
- type Hub
- func (h *Hub) AddRejected()
- func (h *Hub) Broadcast(msg []byte)
- func (h *Hub) ClientCount() int
- func (h *Hub) ClientsForTest() []chan []byte
- func (h *Hub) EvictForTest(ch chan []byte)
- func (h *Hub) Evicted() int64
- func (h *Hub) MaxClients() int64
- func (h *Hub) Register(ch chan []byte) bool
- func (h *Hub) Rejected() int64
- func (h *Hub) SetMaxClients(n int64)
- func (h *Hub) Unregister(ch chan []byte)
Constants ¶
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 (*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 ¶
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 ¶
ClientCount returns the number of connected clients.
func (*Hub) ClientsForTest ¶
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 ¶
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) MaxClients ¶
MaxClients returns the current connection cap (0 = uncapped).
func (*Hub) Register ¶
Register adds the client channel to the hub. It reports false — without registering — when the hub is already at the connection cap.
func (*Hub) SetMaxClients ¶
SetMaxClients sets the connection cap (0 disables it). Existing connections are not evicted when the cap is lowered.
func (*Hub) Unregister ¶
Unregister removes the client channel from the hub.