sse

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package sse reads server-sent event streams (text/event-stream), as defined by the HTML Living Standard. It is built for load generation: a Reader reuses its buffers, so reading an event does not allocate once the buffers have grown to the stream's largest event.

Index

Constants

This section is empty.

Variables

View Source
var ErrTooLarge = errors.New("sse: event larger than the limit")

ErrTooLarge is returned when one event or line exceeds the reader's limit.

Functions

This section is empty.

Types

type Event

type Event struct {
	// Type is the event field, or "message" when the stream sets none.
	Type string
	ID   string
	Data []byte
}

Event is one dispatched event. Data is only valid until the next call to Next; copy it to keep it.

type Reader

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

Reader parses events from a stream.

func NewReader

func NewReader(r io.Reader, limit int) *Reader

NewReader reads events from r. An event or line larger than limit bytes stops the stream with ErrTooLarge; limit <= 0 means 10 MiB.

func (*Reader) BytesRead

func (r *Reader) BytesRead() int64

BytesRead is the number of bytes consumed from the stream so far.

func (*Reader) Next

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

Next returns the next event. It returns io.EOF when the stream ends; a trailing event without its terminating blank line is discarded, as the standard requires.

Jump to

Keyboard shortcuts

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