stream

package
v1.18.2 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: Apache-2.0 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

Index

Constants

View Source
const DefaultMaxBytes = 8 << 20

Variables

This section is empty.

Functions

This section is empty.

Types

type CompletionHook

type CompletionHook func(summary SessionSummary, events []*Event)

type Config

type Config struct {
	BufferSize     int
	ListenerBuffer int
	DropPolicy     DropPolicy
	MaxBytes       bytesize.Budget
}

type Direction

type Direction int
const (
	DirNA Direction = iota
	DirSend
	DirReceive
)

type DropPolicy

type DropPolicy int
const (
	DropNewest DropPolicy = iota
	DropOldest
	DropListener
)

type Event

type Event struct {
	Kind      Kind
	Direction Direction
	Timestamp time.Time
	Sequence  uint64

	// Metadata carries SSE and gRPC details. WebSocket events use WS.
	Metadata map[string]string
	Payload  []byte

	SSE SSEMetadata
	WS  WSMetadata
}

func (*Event) Size added in v1.5.0

func (e *Event) Size() int64

type Kind

type Kind int
const (
	KindSSE Kind = iota
	KindWebSocket
	KindGRPC
)

type Listener

type Listener struct {
	C        <-chan *Event
	Cancel   func()
	Snapshot Snapshot
	// contains filtered or unexported fields
}

func (Listener) Dropped added in v1.5.0

func (l Listener) Dropped() uint64

Dropped counts the events this listener never received. Events lost before it subscribed are counted by Snapshot.Evicted instead.

type Manager

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

func NewManager

func NewManager() *Manager

func (*Manager) AddCompletionHook

func (m *Manager) AddCompletionHook(id string, hook CompletionHook) bool

func (*Manager) Cancel

func (m *Manager) Cancel(id string) bool

func (*Manager) Get

func (m *Manager) Get(id string) (SessionSummary, bool)

func (*Manager) List

func (m *Manager) List() []SessionSummary

func (*Manager) Register

func (m *Manager) Register(session *Session) SessionSummary

func (*Manager) Snapshot

func (m *Manager) Snapshot(id string) ([]*Event, bool)

type SSEMetadata

type SSEMetadata struct {
	Index   int
	Name    string
	ID      string
	Comment string
	Retry   int
}

type Session

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

func NewSession

func NewSession(parent context.Context, kind Kind, cfg Config) *Session

func (*Session) Cancel

func (s *Session) Cancel()

func (*Session) Close

func (s *Session) Close(err error)

func (*Session) Context

func (s *Session) Context() context.Context

func (*Session) Done

func (s *Session) Done() <-chan struct{}

func (*Session) Err

func (s *Session) Err() error

func (*Session) EventsSnapshot

func (s *Session) EventsSnapshot() []*Event

func (*Session) ID

func (s *Session) ID() string

func (*Session) Kind

func (s *Session) Kind() Kind

func (*Session) MarkClosing

func (s *Session) MarkClosing()

func (*Session) MarkOpen

func (s *Session) MarkOpen()

func (*Session) Publish

func (s *Session) Publish(evt *Event)

func (*Session) State

func (s *Session) State() (State, error)

func (*Session) StatsSnapshot

func (s *Session) StatsSnapshot() Stats

func (*Session) Subscribe

func (s *Session) Subscribe() Listener

Subscribe returns the events still to come plus a snapshot of the ones already published. A session that has ended hands back a closed channel, so a late subscriber reads the transcript and stops instead of waiting on a listener that nothing will ever write to.

type SessionSummary

type SessionSummary struct {
	ID        string
	Kind      Kind
	State     State
	Err       error
	StartedAt time.Time
	EndedAt   time.Time
}

type Snapshot

type Snapshot struct {
	Events  []*Event
	State   State
	Err     error
	Evicted uint64
}

type State

type State int
const (
	StateConnecting State = iota
	StateOpen
	StateClosing
	StateClosed
	StateFailed
)

type Stats

type Stats struct {
	StartedAt   time.Time
	EndedAt     time.Time
	EventsTotal uint64
	BytesTotal  uint64
	Dropped     uint64
	Evicted     uint64
}

type WSCloseCode added in v1.13.0

type WSCloseCode int

WSCloseCode is a close status code from RFC 6455 section 7.4.

const WSCloseNormal WSCloseCode = 1000

type WSClosedBy added in v1.13.0

type WSClosedBy string

WSClosedBy names what ended a WebSocket session.

const (
	WSClosedByServer   WSClosedBy = "server"
	WSClosedByClient   WSClosedBy = "client"
	WSClosedByTimeout  WSClosedBy = "timeout"
	WSClosedByCanceled WSClosedBy = "canceled"
	WSClosedByError    WSClosedBy = "error"
)

type WSMetadata

type WSMetadata struct {
	Type WSType
	// Step labels what sent the frame: a @ws step, the console, or the close
	// resterm sends after the last step.
	Step string
	// ClosedBy, Code and Reason describe how the session ended. Code is set
	// only on a close frame.
	ClosedBy WSClosedBy
	Code     WSCloseCode
	Reason   string
}

type WSType added in v1.13.0

type WSType string

WSType names a WebSocket frame the way transcripts show it. It is the opcode's name, except that a text frame sent as JSON is "json".

const (
	WSText   WSType = "text"
	WSJSON   WSType = "json"
	WSBinary WSType = "binary"
	WSPing   WSType = "ping"
	WSPong   WSType = "pong"
	WSClose  WSType = "close"
)

Jump to

Keyboard shortcuts

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