Go library for HTML5 server-sent events
Top 66.5% on sourcepulse
This Go library provides a fully spec-compliant implementation of HTML5 Server-Sent Events (SSE) for both server and client use cases. It's designed for developers building applications that require real-time, one-way communication, such as streaming LLM responses, live notifications, or data feeds, offering a robust and flexible solution for integrating SSE functionality into Go applications.
How It Works
The library offers decoupled server and client implementations. The server component is framework-agnostic and relies on a Provider
interface for message dispatching, allowing integration with external pub-sub systems like Redis or Kafka, or using the built-in "Joe" provider for in-memory pub-sub. Joe can be configured with Replayer
implementations to manage event history and replayability. The client component uses net/http
and the cenkalti/backoff
library for robust connection management, including automatic retries and reconnection logic.
Quick Start & Requirements
go get -u github.com/tmaxmax/go-sse
Highlighted Details
range-over-func
) for event reading, with a fallback for Go 1.22 via GOEXPERIMENT=rangefunc
.sse.Read
function simplifies consuming SSE streams, particularly useful for LLM API responses.sse.Server
implements http.Handler
for easy integration with existing HTTP servers.Joe
provider includes Replayer
interfaces for managing in-memory event history and replayability.Maintenance & Community
Licensing & Compatibility
Limitations & Caveats
Replayer
implementations store events in memory, which may not be suitable for very high-volume or long-term persistence requirements without custom provider/replayer implementations.2 months ago
1 day