sse

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2026 License: MIT Imports: 6 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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