package module
v0.0.0-...-197cba8 Latest Latest

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

Go to latest
Published: Sep 22, 2013 License: Apache-2.0 Imports: 7 Imported by: 1




This section is empty.


View Source
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


This section is empty.


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

func (*Event) WriteTo

func (e *Event) WriteTo(w io.Writer) (int64, error)

WriteTo writes the wire encoding of the event to the given wire.

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 New

func New() *EventSource

New creates a new EventSource.

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.

Jump to

Keyboard shortcuts

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