sse: github.com/go-rfc/sse Index | Files | Directories

package sse

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

Package sse provides the utilities to connect and process events from an HTML5 Server-Sent Events endpoint.

Index

Package Files

decoder.go decoder_go1.6.go doc.go encoder.go eventsource.go message_event.go readystate.go readystate_string.go scanlines.go status.go test_helpers.go

Variables

var (
    // ErrContentType error indicates the content-type header is not accepted
    ErrContentType = errors.New("eventsource: the content type of the stream is not allowed")
)

type Decoder Uses

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

Decoder accepts an io.Reader input and decodes message events from it.

func NewDecoder Uses

func NewDecoder(in io.Reader) *Decoder

NewDecoder returns a Decoder with a growing buffer. Lines are limited to bufio.MaxScanTokenSize - 1.

func NewDecoderSize Uses

func NewDecoderSize(in io.Reader, bufferSize int) *Decoder

NewDecoderSize returns a Decoder with a fixed buffer size. This constructor is only available on go >= 1.6

func (*Decoder) Decode Uses

func (d *Decoder) Decode() (*MessageEvent, error)

Decode reads the input stream and parses events from it. Any error while reading is returned.

func (*Decoder) Retry Uses

func (d *Decoder) Retry() int

Retry returns the amount of milliseconds to wait before attempting to reconnect to the event source.

type Encoder Uses

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

func NewEncoder Uses

func NewEncoder(out io.Writer) *Encoder

func (*Encoder) SetRetry Uses

func (e *Encoder) SetRetry(retryDelayInMillis int)

func (*Encoder) Write Uses

func (e *Encoder) Write(event *MessageEvent) (int, error)

type EventSource Uses

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

EventSource connects and processes events from an HTTP server-sent events stream.

func NewEventSource Uses

func NewEventSource(url string) (*EventSource, error)

NewEventSource connects and returns an EventSource.

func (*EventSource) Close Uses

func (es *EventSource) Close(err error)

Close the event source. Once closed, the event source cannot be re-used again.

func (*EventSource) MessageEvents Uses

func (es *EventSource) MessageEvents() <-chan *MessageEvent

MessageEvents returns a channel of received events.

func (*EventSource) ReadyState Uses

func (es *EventSource) ReadyState() <-chan Status

ReadyState exposes a channel with updates on the ready state of the event source. It must be consumed together with MessageEvents.

func (*EventSource) URL Uses

func (es *EventSource) URL() string

URL returns the event source URL.

type MessageEvent Uses

type MessageEvent struct {
    LastEventID string
    Name        string
    Data        string
}

MessageEvent presents the payload being parsed from an EventSource.

type ReadyState Uses

type ReadyState uint16

ReadyState indicates the state of the EventSource.

const (
    // Connecting while trying to establish connection with the stream.
    Connecting ReadyState = iota
    // Open after connection is established with the server.
    Open
    // Closing after Close is invoked.
    Closing
    // Closed after the connection is closed.
    Closed
)

func (ReadyState) String Uses

func (i ReadyState) String() string

type Status Uses

type Status struct {
    ReadyState ReadyState
    Err        error
}

Status groups together a ready state and possible error associated with it. Useful to notify changes and why they happened.

func (*Status) Error Uses

func (s *Status) Error() string

Directories

PathSynopsis
internal/testutils

Package sse imports 10 packages (graph). Updated 2020-10-12. Refresh now. Tools for package owners.