ssefiber

package
v0.65.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package ssefiber provides adapter-neutral SSE route helpers backed by the transport-neutral eventstream package. The package owns SSE framing, resume handling, retry directives, heartbeat control frames, stream-gap signaling, and route mounting concerns; it does not change the generic stream contract itself.

Mount supports streaming go-router backends. MountFiber retains the legacy Fiber v2 entry point. Hosts cancel owned stream contexts before shutdown; transport reader closure cancels subscriptions on client disconnect.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Handler

func Handler(opts ...Option) router.HandlerFunc

Handler returns the public go-router handler surface for SSE.

func Mount added in v0.63.0

func Mount[T any](r router.Router[T], opts ...Option) error

Mount registers the SSE handler on any streaming go-router backend.

func MountFiber

func MountFiber(r router.Router[*fiber.App], opts ...Option) error

MountFiber registers the SSE handler on a Fiber-backed go-router router.

Types

type Config

type Config struct {
	Path                 string
	Stream               eventstream.Stream
	ScopeResolver        ScopeResolver
	Middlewares          []router.MiddlewareFunc
	HeartbeatInterval    time.Duration
	RetryInterval        time.Duration
	CursorQueryParam     string
	HeartbeatQueryParam  string
	RetryQueryParam      string
	AllowClientTuning    bool
	MinHeartbeatInterval time.Duration
	MaxHeartbeatInterval time.Duration
	MinRetryInterval     time.Duration
	MaxRetryInterval     time.Duration
}

Config defines the public SSE mount and handler surface.

type Option

type Option func(*Config)

Option mutates SSE mount and handler configuration.

func WithAllowClientTuning

func WithAllowClientTuning(allow bool) Option

WithAllowClientTuning enables opt-in query-param tuning for heartbeat/retry.

func WithCursorQueryParam

func WithCursorQueryParam(name string) Option

WithCursorQueryParam overrides the fallback cursor query parameter name.

func WithHeartbeatBounds

func WithHeartbeatBounds(min, max time.Duration) Option

WithHeartbeatBounds overrides accepted heartbeat tuning limits.

func WithHeartbeatInterval

func WithHeartbeatInterval(interval time.Duration) Option

WithHeartbeatInterval overrides the default heartbeat interval.

func WithHeartbeatQueryParam

func WithHeartbeatQueryParam(name string) Option

WithHeartbeatQueryParam overrides the heartbeat tuning query parameter name.

func WithMiddlewares

func WithMiddlewares(middlewares ...router.MiddlewareFunc) Option

WithMiddlewares appends middleware only for the mounted SSE route.

func WithPath

func WithPath(path string) Option

WithPath overrides the mounted route path.

func WithRetryBounds

func WithRetryBounds(min, max time.Duration) Option

WithRetryBounds overrides accepted retry tuning limits.

func WithRetryInterval

func WithRetryInterval(interval time.Duration) Option

WithRetryInterval overrides the default retry interval.

func WithRetryQueryParam

func WithRetryQueryParam(name string) Option

WithRetryQueryParam overrides the retry tuning query parameter name.

func WithScopeResolver

func WithScopeResolver(resolver ScopeResolver) Option

WithScopeResolver configures request-to-scope resolution.

func WithStream

func WithStream(stream eventstream.Stream) Option

WithStream configures the backing event stream.

type ScopeResolver

type ScopeResolver func(router.Context) (eventstream.Scope, error)

ScopeResolver maps request state into an eventstream subscription scope.

Jump to

Keyboard shortcuts

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