sse

package
v0.0.0-...-4308b5e Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultSSEClient = &http.Client{Timeout: 0}

DefaultSSEClient is the default client to use when connecting to a SSE endpoint. It's configured with no timeout so that it can stay connected indefinitely receiving events.

View Source
var ReconnectDelay = 1 * time.Second

The amount of time the client should wait between reconnecting to the SSE endpoint.

Functions

func Open

func Open(ctx context.Context, url string) <-chan Event

func OpenWithClient

func OpenWithClient(ctx context.Context, client *http.Client, url string) <-chan Event

func ReadEvents

func ReadEvents(in io.Reader, events chan<- Event) error

ReadEvents parses and interprets an event stream according to the W3C working draft for Server-Sent Events found at: https://www.w3.org/TR/2009/WD-eventsource-20090421. If a non-EOF error occurs while reading data then it is returned.

func RunOnce

func RunOnce(ctx context.Context, client *http.Client, url string, events chan<- Event) error

RunOnce will use the provided HTTP client to connect to the specified URL and process the resulting response as a Server-Sent event stream. Currently only an HTTP status code of 200 is allowed.

Types

type Event

type Event struct {
	Name string
	ID   string
	Data []byte
}

Jump to

Keyboard shortcuts

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