go-sse: github.com/vito/go-sse/sse Index | Files

package sse

import "github.com/vito/go-sse/sse"

Index

Package Files

errors.go event.go event_source.go read_closer.go

Variables

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

type BadResponseError Uses

type BadResponseError struct {
    Response *http.Response
}

func (BadResponseError) Error Uses

func (err BadResponseError) Error() string

type Config Uses

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

func (*Config) Connect Uses

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

type Event Uses

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

func (Event) Encode Uses

func (event Event) Encode() string

func (Event) Write Uses

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

type EventSource Uses

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 Uses

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

func NewEventSource Uses

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

func (*EventSource) Close Uses

func (source *EventSource) Close() error

func (*EventSource) Next Uses

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

type ReadCloser Uses

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

func NewReadCloser Uses

func NewReadCloser(source io.ReadCloser) *ReadCloser

func (*ReadCloser) Close Uses

func (rc *ReadCloser) Close() error

func (*ReadCloser) Next Uses

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

type RetryParams Uses

type RetryParams struct {
    RetryInterval time.Duration
    MaxRetries    uint16
}

Package sse imports 9 packages (graph) and is imported by 82 packages. Updated 2016-07-23. Refresh now. Tools for package owners.