Documentation ¶
Overview ¶
Package broker contains types to be used to host a Server Sent Events broker.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Broker ¶
type Broker interface { Broadcast(evt *event.Event) error BroadcastTo(id string, evt *event.Event) error Listen() <-chan *event.Event ClientHandler(w http.ResponseWriter, r *http.Request) EventHandler(w http.ResponseWriter, r *http.Request) }
The Broker interface describes the Server Side Events broker, propagating messages to all connected clients.
func New ¶
func New(timeout time.Duration, tolerance int, eh ErrorHandler) Broker
New creates a new instance of the Broker type. The 'timeout' parameter determines how long the broker will wait to write a message to a client, if this timeout is exceeded, the client will not receive that message. The 'tolerance' parameter indicates how many sequential errors can occur when communicating with a client until the client is forcefully disconnected. The 'eh' parameter is a custom HTTP error handler that the broker will use when HTTP errors are raised. If 'eh' is null, the default http.Error method is used.
type ErrorHandler ¶
type ErrorHandler func(w http.ResponseWriter, r *http.Request, err error)
ErrorHandler is a convenience wrapper for the HTTP error handling function.