esource: kylelemons.net/go/esource Index | Files

package esource

import "kylelemons.net/go/esource"

Index

Package Files

esource.go

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
)

type Event Uses

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 Uses

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

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

type EventSource Uses

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 Uses

func New() *EventSource

New creates a new EventSource.

func (*EventSource) Close Uses

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 Uses

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 Uses

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 Uses

func (es *EventSource) Tee(startID int) ([]Event, chan Event)

Tee delivers the events as they would go to a client.

Package esource imports 7 packages (graph) and is imported by 1 packages. Updated 2018-03-10. Refresh now. Tools for package owners.