sse

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

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 reads Server-Sent Events streams line by line.

bufio.Scanner stops at a fixed token size, so one event larger than its buffer ends the whole stream with "token too long". LineReader reads lines of any length up to a high safety limit instead, and skips a line past that limit (keeping its start, so the caller can tell what it was) rather than failing the stream.

Index

Constants

View Source
const DefaultMaxLine = 64 << 20

DefaultMaxLine is the longest line read whole: well past any event a DocsGPT server sends, but a bound on what one line can make the client hold.

View Source
const PrefixBytes = 4096

PrefixBytes is how much of an oversized line is kept, enough to read the event's type.

Variables

This section is empty.

Functions

func FrameType

func FrameType(line []byte) string

FrameType is the event type named in a “data:“ line (or the start of one), or "" when it can't be told.

Types

type Line

type Line struct {
	// Text is the line without its line ending; for an oversized line, only
	// its first PrefixBytes.
	Text []byte
	// Oversized marks a line longer than the reader's limit, which was skipped.
	Oversized bool
	// Size is the line's full length in bytes, line ending excluded.
	Size int
}

Line is one line of the stream.

type LineReader

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

LineReader reads newline-terminated lines with no fixed buffer cap.

func NewLineReader

func NewLineReader(r io.Reader, max int) *LineReader

NewLineReader reads lines from r, reading whole those up to max bytes.

func (*LineReader) Next

func (l *LineReader) Next() (Line, error)

Next returns the next line. At the end of the stream it returns io.EOF, after any final line that had no line ending.

Jump to

Keyboard shortcuts

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