sse

package
v0.36.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package sse provides a tiny Server-Sent Events server with pluggable routes. No external deps; safe for quick demos and small dashboards.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Addr is the listening address, e.g. ":8080" or "127.0.0.1:0".
	Addr string

	// IndexPath is the path serving a minimal live HTML page ("" to disable).
	// e.g. "/" or "/status"
	IndexPath string

	// StreamPath is the SSE endpoint path, e.g. "/stream".
	StreamPath string

	// Title for the index page (cosmetic).
	Title string

	// AllowCORS, if true, sets Access-Control-Allow-Origin: * for /stream.
	AllowCORS bool

	// ClientBuf is the per-client buffered message queue size.
	// If 0, defaults to 16. When full, new messages are dropped for that client.
	ClientBuf int

	// Heartbeat sends a comment line every interval to keep connections alive.
	// If 0, defaults to 25s.
	Heartbeat time.Duration

	// Logger (optional). If nil, log.Printf is used.
	Logger *log.Logger
}

Options configures the SSE server.

type Server

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

Server is a simple SSE broadcaster.

func New

func New(opts Options) *Server

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the HTTP server (blocking).

func (*Server) Publish

func (s *Server) Publish(payload string)

Publish broadcasts a new payload to all clients and stores it as latest.

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown gracefully stops the server.

Jump to

Keyboard shortcuts

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