Documentation
¶
Overview ¶
Package sse provides a small Server-Sent Events handler for Fiber.
The package focuses on the SSE transport: response headers, wire formatting, flushing, heartbeat comments, and disconnect detection via flush errors. Application-specific concerns such as topics, replay storage, authentication, and pub/sub fan-out intentionally stay outside the core middleware.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ConfigDefault = Config{ Handler: nil, OnClose: nil, Retry: 0, HeartbeatInterval: 15 * time.Second, DisableHeartbeat: false, }
ConfigDefault is the default config.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Handler writes events to the stream.
//
// Required.
Handler Handler
// OnClose is called after the stream handler returns or the client disconnects.
//
// Optional. Default: nil
OnClose func(c fiber.Ctx, err error)
// Retry controls the reconnection delay sent to clients.
// Values less than or equal to zero disable the initial retry field.
//
// Optional. Default: 0
Retry time.Duration
// HeartbeatInterval controls comment heartbeats used to keep intermediaries
// from closing idle streams and to detect disconnected clients.
// When DisableHeartbeat is false, values less than or equal to zero are
// replaced by the default interval.
//
// Optional. Default: 15 * time.Second
HeartbeatInterval time.Duration
// DisableHeartbeat disables automatic comment heartbeats.
//
// Optional. Default: false
DisableHeartbeat bool
}
Config defines the config for the SSE handler.
type Event ¶
type Event struct {
// Data is written as one or more data fields. Strings and byte slices are
// written as-is; other values are JSON encoded.
Data any
// ID sets the SSE id field.
ID string
// Name sets the SSE event field.
Name string
// Retry sets the SSE retry field for this event.
Retry time.Duration
}
Event defines a single Server-Sent Event frame.
type Stream ¶
type Stream struct {
// contains filtered or unexported fields
}
Stream is an active SSE response stream.
func (*Stream) Done ¶
func (s *Stream) Done() <-chan struct{}
Done returns a channel closed when a write fails or the handler returns.
func (*Stream) LastEventID ¶
LastEventID returns the Last-Event-ID header value sent by the client.