sse

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrLineTooLarge  = errors.New("sse: line too large")
	ErrEventTooLarge = errors.New("sse: event too large")
)

Functions

This section is empty.

Types

type Event

type Event struct {
	Type  string
	Data  string
	ID    string
	Retry string
}

Event is a parsed SSE event.

type Scanner

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

Scanner reads SSE events from an io.Reader.

§17.1 Zero-copy optimization: uses ReadSlice for zero-alloc line reads, accumulates data in a reusable byte buffer, and defers string conversion to Event()/UnsafeEvent() access time.

func NewScanner

func NewScanner(r io.Reader) *Scanner

NewScanner creates a scanner with default resource limits.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the scanner terminal error.

func (*Scanner) Event

func (s *Scanner) Event() Event

Event returns the most recently parsed event with safe string Data.

func (*Scanner) Next

func (s *Scanner) Next() bool

Next parses the next SSE event.

func (*Scanner) SetLimits

func (s *Scanner) SetLimits(maxLineBytes, maxEventBytes int)

SetLimits overrides per-line and per-event byte limits.

func (*Scanner) UnsafeEvent

func (s *Scanner) UnsafeEvent() Event

UnsafeEvent returns the event with zero-copy Data backed by internal buffers. The returned Event.Data is only valid until the next call to Next(). Use for hot paths where the caller processes data immediately.

Jump to

Keyboard shortcuts

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