sse

package
v0.9.12 Latest Latest
Warning

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

Go to latest
Published: Feb 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleSSE

func HandleSSE(broker *Broker) forge.SSEHandler

HandleSSE returns a forge SSE handler that connects clients to the broker. The handler runs for the lifetime of the client connection, sending keep-alive comments at the configured interval. The broker broadcasts events to all connected clients.

Types

type Broker

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

Broker manages SSE client connections and broadcasts events.

func NewBroker

func NewBroker(keepAlive time.Duration, logger forge.Logger) *Broker

NewBroker creates a new SSE event broker.

func (*Broker) AddClient

func (b *Broker) AddClient(stream forge.Stream) string

AddClient registers a new SSE stream as a client. Returns the client ID for later removal.

func (*Broker) Broadcast

func (b *Broker) Broadcast(event Event)

Broadcast sends an event to all connected clients. Failed sends are logged and the client is removed.

func (*Broker) BroadcastJSON

func (b *Broker) BroadcastJSON(eventType EventType, data interface{})

BroadcastJSON sends a JSON event to all connected clients.

func (*Broker) ClientCount

func (b *Broker) ClientCount() int

ClientCount returns the number of connected clients.

func (*Broker) Close

func (b *Broker) Close()

Close shuts down the broker and disconnects all clients.

func (*Broker) KeepAlive

func (b *Broker) KeepAlive() time.Duration

KeepAlive returns the configured keep-alive interval.

func (*Broker) RemoveClient

func (b *Broker) RemoveClient(id string)

RemoveClient removes a client by ID.

type Event

type Event struct {
	Type EventType   `json:"type"`
	Data interface{} `json:"data"`
}

Event is a single SSE event to broadcast to all connected clients.

type EventType

type EventType string

EventType identifies the kind of SSE event sent to clients.

const (
	EventHealthUpdate  EventType = "health-update"
	EventMetricsUpdate EventType = "metrics-update"
	EventWidgetRefresh EventType = "widget-refresh"
	EventNotification  EventType = "notification"
	EventNavBadge      EventType = "nav-badge-update"
)

Jump to

Keyboard shortcuts

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