sse

package
v0.0.16 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

README

sse

import "github.com/agentstation/starmap/internal/server/sse"

Package sse provides Server-Sent Events support for real-time updates.

Index

type Broadcaster

Broadcaster manages Server-Sent Events connections.

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

func NewBroadcaster
func NewBroadcaster(logger *zerolog.Logger) *Broadcaster

NewBroadcaster creates a new SSE broadcaster.

func (*Broadcaster) Broadcast
func (b *Broadcaster) Broadcast(event Event)

Broadcast sends an event to all connected SSE clients.

func (*Broadcaster) ClientCount
func (b *Broadcaster) ClientCount() int

ClientCount returns the number of connected SSE clients.

func (*Broadcaster) Run
func (b *Broadcaster) Run(ctx context.Context)

Run starts the broadcaster's main loop. Should be called in a goroutine. The broadcaster will run until the context is cancelled.

func (*Broadcaster) ServeHTTP
func (b *Broadcaster) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles SSE connections.

type Event

Event represents an SSE event.

type Event struct {
    Event string `json:"event,omitempty"` // Event type (optional)
    ID    string `json:"id,omitempty"`    // Event ID (optional)
    Data  any    `json:"data"`            // Event data
}

Generated by gomarkdoc

Documentation

Overview

Package sse provides Server-Sent Events support for real-time updates.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster manages Server-Sent Events connections.

func NewBroadcaster

func NewBroadcaster(logger *zerolog.Logger) *Broadcaster

NewBroadcaster creates a new SSE broadcaster.

func (*Broadcaster) Broadcast

func (b *Broadcaster) Broadcast(event Event)

Broadcast sends an event to all connected SSE clients.

func (*Broadcaster) ClientCount

func (b *Broadcaster) ClientCount() int

ClientCount returns the number of connected SSE clients.

func (*Broadcaster) Run

func (b *Broadcaster) Run(ctx context.Context)

Run starts the broadcaster's main loop. Should be called in a goroutine. The broadcaster will run until the context is cancelled.

func (*Broadcaster) ServeHTTP

func (b *Broadcaster) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP handles SSE connections.

type Event

type Event struct {
	Event string `json:"event,omitempty"` // Event type (optional)
	ID    string `json:"id,omitempty"`    // Event ID (optional)
	Data  any    `json:"data"`            // Event data
}

Event represents an SSE event.

Jump to

Keyboard shortcuts

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