Help us shape the future of Go! Take the 2026 Go Developer Survey

stream

package
v0.1.23 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseStreamReader

type BaseStreamReader[T any] struct {
	// contains filtered or unexported fields
}

BaseStreamReader provides generic SSE stream reading capabilities

func NewBaseStreamReader

func NewBaseStreamReader[T any](ctx context.Context, resp *http.Response, parser SSEParser[T]) *BaseStreamReader[T]

NewBaseStreamReader creates a new base stream reader

func (*BaseStreamReader[T]) Close

func (r *BaseStreamReader[T]) Close() error

Close closes the stream reader and releases resources

func (*BaseStreamReader[T]) Recv

func (r *BaseStreamReader[T]) Recv() (T, error)

Recv receives the next item from the stream

type SSEDecoder

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

SSEDecoder decodes Server-Sent Events from an io.Reader

func NewSSEDecoder

func NewSSEDecoder(reader io.Reader) *SSEDecoder

NewSSEDecoder creates a new SSE decoder

func (*SSEDecoder) Decode

func (d *SSEDecoder) Decode(ctx context.Context) <-chan SSEEvent

Decode decodes SSE events from the reader and returns a channel

func (*SSEDecoder) DecodeEvent

func (d *SSEDecoder) DecodeEvent() (*ServerSentEvent, error)

DecodeEvent decodes a single SSE event

type SSEEvent

type SSEEvent struct {
	Event *ServerSentEvent
	Error error
}

SSEEvent wraps either an event or an error

type SSEParser

type SSEParser[T any] interface {
	Parse(sse *ServerSentEvent) (T, error)
	HandleError(sse *ServerSentEvent) error
}

SSEParser defines the interface for parsing SSE events into specific types

type ServerSentEvent

type ServerSentEvent struct {
	Event string
	Data  string
	ID    string
	Retry *int
}

ServerSentEvent represents a Server-Sent Event

func (*ServerSentEvent) JSON

func (sse *ServerSentEvent) JSON(v interface{}) error

JSON unmarshals the Data field into the provided interface

Jump to

Keyboard shortcuts

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