Documentation
¶
Overview ¶
Package sse provides a Server-Sent Events broker for pushing real-time events to connected clients, scoped by user ID.
Index ¶
- type Broker
- func (b *Broker) Broadcast(eventType string, data any)
- func (b *Broker) ClientCount(userID string) int
- func (b *Broker) Close()
- func (b *Broker) Done() <-chan struct{}
- func (b *Broker) Publish(userID string, eventType string, data any)
- func (b *Broker) Subscribe(userID string) chan Event
- func (b *Broker) Unsubscribe(userID string, ch chan Event)
- type Event
- type Handler
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker struct {
// contains filtered or unexported fields
}
Broker manages per-user SSE client channels.
func (*Broker) ClientCount ¶
ClientCount returns the number of connected clients for a user.
func (*Broker) Close ¶
func (b *Broker) Close()
Close signals all SSE handlers to exit and closes all client channels.
func (*Broker) Done ¶
func (b *Broker) Done() <-chan struct{}
Done returns a channel that is closed when the broker is shut down.
func (*Broker) Publish ¶
Publish sends an event to all subscribers of the given user. Non-blocking: if a client's buffer is full, the event is dropped.
func (*Broker) Subscribe ¶
Subscribe creates a new event channel for the given user. The caller must call Unsubscribe when done.
func (*Broker) Unsubscribe ¶
Unsubscribe removes a client channel. Only closes the channel if it hasn't already been closed by Close().
type Event ¶
Event represents a server-sent event.
func (Event) MarshalData ¶
MarshalData returns the JSON-encoded data field.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves the SSE event stream endpoint.
func (*Handler) RegisterRoutes ¶
RegisterRoutes registers the SSE endpoint on the given echo group.