Documentation
¶
Overview ¶
Package sse provides a small, dependency-free helper for writing Server-Sent Events that follows the WHATWG `text/event-stream` spec.
SPECIFICATIONS.md §5.6: events carry an `id` for `Last-Event-ID` reconnect, a `retry` hint, and we emit a periodic comment heartbeat (`:keepalive\n\n`) to keep idle proxies open.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LastEventID ¶
LastEventID returns the value of the Last-Event-ID header, or empty.
Types ¶
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer represents a single SSE connection. Use New() to construct one.
func New ¶
func New(w http.ResponseWriter) (*Writer, error)
New writes the standard SSE response headers and returns a Writer. It returns an error if the underlying ResponseWriter does not support flushing (e.g. when used behind an http.ResponseRecorder).
func (*Writer) HeartbeatLoop ¶
HeartbeatLoop emits a heartbeat every interval until ctx is cancelled or the writer fails. Run it from a goroutine alongside your event pump.