Keywords: Golang SSE, Server-Sent Events, SSE Reader, SSE Parser, Go SSE Client
sse is a lightweight, fully spec compliant Server-Sent Events (SSE) reader library for Go. It provides a simple wrapper over an io.Reader
(typically an HTTP response body) so you can easily handle streaming SSE events in your Go applications. The design is really simple, easy to use, and perfect for developers looking to implement real-time event handling in a minimalistic way.
go get github.com/dblokhin/sse
sse.Read
returns iterator, so it is a straightforward way to handle SSE stream data from an io.Reader
source:
// ...
// Use the sse.Read iterator directly in a range loop.
for event, err := range sse.Read(resp.Body) {
if err != nil {
// error handling ...
}
// process the valid event.
fmt.Println("received event:", event)
}
}
Any invalid SSE line sequence is returned as an error (ErrInvalidSequence
) with detailed message content, allowing graceful handling or logging of issues.
MIT License