stream

package
v0.1.18-rc1 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDone = errors.New("stream: done")

ErrDone signals that the consumer has finished processing the stream.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPClient  *http.Client
	MaxRetries  int           // -1 for unlimited retries
	IdleTimeout time.Duration // optional: cancel stream if no events for this duration
	Logger      *slog.Logger  // optional: logger for backoff and reconnect events
}

Client streams server-sent events with reconnection semantics.

func (Client) Stream

func (c Client) Stream(ctx context.Context, endpoint string, handler func(Event) error) error

Stream consumes events from the endpoint and invokes handler for each event. The handler may return ErrDone to stop streaming gracefully.

type Event

type Event struct {
	ID    string
	Type  string
	Data  []byte
	Retry time.Duration
}

Event represents a server-sent event frame.

Jump to

Keyboard shortcuts

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