eventstream

package
v1.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Stream

type Stream struct {

	// Events emits the events received by the stream
	Events chan StreamEvent
	Ready  chan bool
	// Errors emits any errors encountered while reading events from the stream.
	// It's mainly for informative purposes - the client isn't required to take any
	// action when an error is encountered. The stream will always attempt to continue,
	// even if that involves reconnecting to the server.
	Errors chan error
	// Logger is a logger that, when set, will be used for logging debug messages
	Logger *log.Logger
	// contains filtered or unexported fields
}

Stream handles a connection for receiving Server Sent Events. It will try and reconnect if the connection is lost, respecting both received retry delays and event id's.

func Subscribe

func Subscribe(url, lastEventID string) (*Stream, error)

Subscribe to the Events emitted from the specified url. If lastEventId is non-empty it will be sent to the server in case it can replay missed events.

func SubscribeWith

func SubscribeWith(lastEventID string, client *http.Client, request *http.Request) (*Stream, error)

SubscribeWith takes a http client and request providing customization over both headers and control over the http client settings (timeouts, tls, etc)

func SubscribeWithRequest

func SubscribeWithRequest(lastEventID string, request *http.Request) (*Stream, error)

SubscribeWithRequest will take an http.Request to setup the stream, allowing custom headers to be specified, authentication to be configured, etc.

func (*Stream) Close

func (stream *Stream) Close()

Close will close the stream. It is safe for concurrent access and can be called multiple times.

func (*Stream) RetryNow added in v1.11.2

func (stream *Stream) RetryNow()

RetryNow will force the stream to reconnect a disconnected stream immediately.

type StreamEvent

type StreamEvent interface {
	// Id is an identifier that can be used to allow a client to replay
	// missed Events by returning the Last-Event-Id header.
	// Return empty string if not required.
	Id() string
	// The name of the event. Return empty string if not required.
	Event() string
	// The payload of the event.
	Data() string
	Retry() int64
}

type SubscriptionError

type SubscriptionError struct {
	Code    int
	Message string
}

func (SubscriptionError) Error

func (e SubscriptionError) Error() string

Jump to

Keyboard shortcuts

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