sse

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package sse provides an SSE transport for tether. Use it when the deployment environment does not support WebSocket (e.g. certain PaaS providers, corporate proxies, or HTTP/2-only setups).

The transport is unidirectional - server→client only. Updates flow as Server-Sent Events over a long-lived HTTP GET (EventSource on the client side). Client events arrive as individual HTTP POST requests and are routed directly to the session's command channel by the tether handler.

Wire up by passing sse.Upgrade() as the Fallback (or Upgrade) field in [tether.StatefulConfig] and setting Mode to [mode.ServerSentEvents] or [mode.Both].

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Upgrade

func Upgrade(opts ...Options) func(http.ResponseWriter, *http.Request) (xport.Transport, error)

Upgrade returns an upgrade function for use in [tether.StatefulConfig].Fallback (or Upgrade when Mode is mode.ServerSentEvents). When the tether handler receives a GET with Accept: text/event-stream, it calls this function to establish the SSE stream. The stream stays open for the lifetime of the session; server updates are written as SSE "data" lines.

Types

type Options added in v0.2.1

type Options struct {
	// WriteBuffer sets the capacity of the internal channel that
	// buffers encoded updates between the session's command loop and
	// the HTTP response writer. When the channel is full, Send blocks
	// until the writer drains it, stalling the session loop.
	//
	// Increase this for high-frequency update scenarios (live
	// dashboards, streaming data) where the client may fall a few
	// frames behind. The memory cost is small - each slot holds one
	// pre-encoded update (typically a few hundred bytes).
	//
	// Zero uses the default (4).
	WriteBuffer int
}

Options configures the SSE transport.

Jump to

Keyboard shortcuts

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