Documentation ¶
Overview ¶
Package eventsource provides the building blocks for consuming and building EventSource services.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrClosed signals that the event source has been closed and will not be // reopened. ErrClosed = errors.New("closed") // ErrInvalidEncoding is returned by Encoder and Decoder when invalid UTF-8 // event data is encountered. ErrInvalidEncoding = errors.New("invalid UTF-8 sequence") )
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes EventSource events from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads from r.
func (*Decoder) Decode ¶
Decode reads the next event from its input and stores it in the provided Event pointer.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder writes EventSource events to an output stream.
func NewEncoder ¶
NewEncoder returns a new encoder that writes to w.
func (*Encoder) Flush ¶
Flush sends an empty line to signal event is complete, and flushes the writer.
func (*Encoder) WriteField ¶
WriteField writes an event field to the connection. If the provided value contains newlines, multiple fields will be emitted. If the returned error is not nil, it will be either ErrInvalidEncoding or an error from the connection.
type EventSource ¶
type EventSource struct {
// contains filtered or unexported fields
}
An EventSource consumes server sent events over HTTP with automatic recovery.
func New ¶
func New(req *http.Request, retry time.Duration) *EventSource
New prepares an EventSource. The connection is automatically managed, using req to connect, and retrying from recoverable errors after waiting the provided retry duration.
func (*EventSource) Close ¶
func (es *EventSource) Close()
Close the source. Any further calls to Read() will return ErrClosed.
func (*EventSource) Read ¶
func (es *EventSource) Read() (Event, error)
Read an event from EventSource. If an error is returned, the EventSource will not reconnect, and any further call to Read() will return the same error.
type FlushWriter ¶
The FlushWriter interface groups basic Write and Flush methods.