Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ContentType is sent as the content type for event source handlers ContentType = "text/event-stream;charset=utf-8" // BufferSize is the number of events to buffer per connection before dropping BufferSize = 256 // DefaultBacklog is the default number of events to keep in memory DefaultBacklog = 256 )
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct { ID int // set by the esource library Type string // event type (may not contain newlines or colons) Data interface{} // string (sent raw) or object (will be json encoded) or nil (nothing) }
An Event represents data that can be sent to an EventSource
type EventSource ¶
type EventSource struct { // Events receives events to be sent to all listening connections. Events chan<- Event // contains filtered or unexported fields }
An EventSource represents a stream of events that can handle multiple clients.
All methods on EventSource are goroutine-safe, as is sending messages on the Events channel. Methods may not be called and Events may not be sent after the Close method has been called.
func (*EventSource) Close ¶
func (es *EventSource) Close() error
Close causes the EventSource to shut down all connections. The final messages will be flushed to clients asynchronously.
func (*EventSource) ServeHTTP ¶
func (es *EventSource) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP serves the client with events as they come in, and with any stored events
func (*EventSource) SetBacklog ¶
func (es *EventSource) SetBacklog(backlog int)
SetBacklog adjusts the number of messages that will be maintained in memory in order to be able to catch up clients which reconnect. If more events have been stored than the given backlog, the excess events will be discarded immediately.
func (*EventSource) Tee ¶
func (es *EventSource) Tee(startID int) ([]Event, chan Event)
Tee delivers the events as they would go to a client.