Skip to content

dblokhin/sse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSE - Simple and Compliant Server-Sent Events Parser for Go

Go Report Card GoDoc

Keywords: Golang SSE, Server-Sent Events, SSE Reader, SSE Parser, Go SSE Client

Overview

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.

Installation

go get github.com/dblokhin/sse

Usage Example

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)
	}
}

Error Handling

Any invalid SSE line sequence is returned as an error (ErrInvalidSequence) with detailed message content, allowing graceful handling or logging of issues.


License

MIT License

About

Go SSE Client

Resources

License

Stars

Watchers

Forks

Packages

No packages published