Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Stream ¶
func Stream(c *rex.Context, ch <-chan any, opts *StreamOptions) error
Stream sends events from the channel to the client with enhanced error handling and configuration options.
func StreamWithContext ¶
func StreamWithContext(ctx context.Context, w http.ResponseWriter, ch <-chan any, opts *StreamOptions) error
StreamWithContext is a convenience wrapper that uses the provided context for cancellation instead of rex.Context.
Types ¶
type Event ¶
type Event struct {
ID string // Event ID for client tracking
Event string // Event type/name
Data any // Event payload
Retry time.Duration // Reconnection time (converted to milliseconds)
Comment string // Optional comment (for keepalive)
}
Event represents a Server-Sent Event.
func (Event) WithComment ¶
WithComment sets a comment.
type StreamOptions ¶
type StreamOptions struct {
// Headers to set on the response (merged with defaults)
Headers map[string]string
// Retry interval sent to client (0 to omit)
Retry time.Duration
// Enable automatic keepalive comments
Keepalive bool
// Keepalive interval (default: 15s)
KeepaliveInterval time.Duration
// Custom error handler
OnError func(error)
// Custom close handler
OnClose func()
}
StreamOptions configures the SSE stream behavior.
func DefaultOptions ¶
func DefaultOptions() *StreamOptions
DefaultOptions returns sensible defaults for SSE streaming.
Click to show internal directories.
Click to hide internal directories.