ws

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Overview

Package ws implements a Server-Sent Events (SSE) hub for real-time event broadcasting to connected web clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RedactMap

func RedactMap(m map[string]any) map[string]any

RedactMap recursively redacts secrets from string values in a map.

func RedactSecrets

func RedactSecrets(s string) string

RedactSecrets replaces known secret patterns in a string with "***".

Types

type Event

type Event struct {
	Data any    `json:"data"`
	Type string `json:"type"`
}

Event is the payload broadcast to SSE subscribers.

type EventWriter

type EventWriter interface {
	Write(eventType string, data any) error
}

EventWriter persists SSE events for later retrieval.

type Hub

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

Hub manages SSE subscribers and broadcasts events. It implements agent.EventPublisher so it can be wired into AgentService.

func NewHub

func NewHub() *Hub

NewHub creates and returns a new Hub. Call Run() in a goroutine.

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount returns the number of active SSE connections.

func (*Hub) Publish

func (h *Hub) Publish(eventType string, data map[string]any)

Publish implements agent.EventPublisher. Data is redacted before broadcast to prevent secrets from leaking to the UI. If an EventWriter is attached, the event is also persisted to disk.

func (*Hub) Run

func (h *Hub) Run()

Run processes the broadcast channel until Stop is called.

func (*Hub) ServeHTTP

func (h *Hub) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP serves an SSE stream to a single client.

func (*Hub) SetWriter

func (h *Hub) SetWriter(w EventWriter)

SetWriter attaches an EventWriter for persisting broadcast events.

func (*Hub) Stop

func (h *Hub) Stop()

Stop shuts down the hub's Run loop. Safe to call multiple times.

Jump to

Keyboard shortcuts

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