sse

package
Version: v0.0.0-...-fd69d27 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2016 License: Apache-2.0 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 Config

type Config struct {
	Client         *http.Client
	RetryParams    RetryParams
	RequestCreator func() *http.Request
}

func (*Config) Connect

func (c *Config) Connect() (*EventSource, error)

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.

Alternatively, create a Config struct instance and call Connect() and then call Next().

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)

type RetryParams

type RetryParams struct {
	RetryInterval time.Duration
	MaxRetries    uint16
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL