sse

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package sse implements Server-Sent Events parsing and writing per the WHATWG spec (https://html.spec.whatwg.org/multipage/server-sent-events.html).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Type  string // "event:" field; empty string means unnamed event
	Data  string // "data:" field; multiple data lines joined with "\n"
	ID    string // "id:" field
	Retry int    // "retry:" field in milliseconds; 0 means not set
}

Event represents a single Server-Sent Event.

type Reader

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

Reader parses Server-Sent Events from a byte stream.

func NewReader

func NewReader(r io.Reader) *Reader

NewReader creates a Reader that parses SSE from r.

func (*Reader) Next

func (r *Reader) Next() (Event, error)

Next returns the next event from the stream. It returns io.EOF when no more events are available.

type Writer

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

Writer writes Server-Sent Events to an HTTP response.

func NewWriter

func NewWriter(w http.ResponseWriter) (*Writer, error)

NewWriter creates a Writer that writes SSE to w. It returns an error if w does not implement http.Flusher.

func (*Writer) SetHeaders

func (w *Writer) SetHeaders()

SetHeaders sets the standard SSE response headers.

func (*Writer) WriteEvent

func (w *Writer) WriteEvent(e Event) error

WriteEvent writes a single event in SSE wire format and flushes. Returns an error if the underlying writer fails.

Jump to

Keyboard shortcuts

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