sse

package
v0.0.0-...-b61aaf9 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: Apache-2.0, Apache-2.0, BSD-2-Clause-Views, + 2 more Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSourceClosed = errors.New("source closed")

Functions

This section is empty.

Types

type BadResponseError

type BadResponseError struct {
	Response *http.Response
}

func (BadResponseError) Error

func (err BadResponseError) Error() string

type Event

type Event struct {
	ID    string
	Name  string
	Data  []byte
	Retry time.Duration
}

func (Event) Encode

func (event Event) Encode() string

func (Event) Write

func (event Event) Write(destination io.Writer) error

type EventSource

type EventSource struct {
	// contains filtered or unexported fields
}

EventSource behaves like the EventSource interface from the Server-Sent Events spec implemented in many browsers. See http://www.w3.org/TR/eventsource/#the-eventsource-interface for details.

To use, optionally call Connect(), and then call Next(). If Next() is called prior to Connect(), it will connect for you.

Next() is often called asynchronously in a loop so that the event source can be closed. Next() will block on reading from the server.

If Close() is called while reading an event, Next() will return early, and subsequent calls to Next() will return early. To read new events, Connect() must be called.

If an EOF is received, Next() returns io.EOF, and subsequent calls to Next() will return early. To read new events, Connect() must be called.

func Connect

func Connect(client *http.Client, defaultRetryInterval time.Duration, requestCreator func() *http.Request) (*EventSource, error)

func NewEventSource

func NewEventSource(client *http.Client, defaultRetryInterval time.Duration, requestCreator func() *http.Request) *EventSource

func (*EventSource) Close

func (source *EventSource) Close() error

func (*EventSource) Next

func (source *EventSource) Next() (Event, error)

type ReadCloser

type ReadCloser struct {
	// contains filtered or unexported fields
}

func NewReadCloser

func NewReadCloser(source io.ReadCloser) *ReadCloser

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

func (*ReadCloser) Next

func (rc *ReadCloser) Next() (Event, error)

Jump to

Keyboard shortcuts

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