Categorygithub.com/launchdarkly/eventsource
modulepackage
1.8.0
Repository: https://github.com/launchdarkly/eventsource.git
Documentation: pkg.go.dev

# README

GoDoc Actions Status

Eventsource

Eventsource implements a Go implementation of client and server to allow streaming data one-way over a HTTP connection using the Server-Sent Events API http://dev.w3.org/html5/eventsource/

This is a fork of: https://github.com/donovanhide/eventsource

Supported Go versions

The library supports the 'latest' and 'penultimate' Go versions defined in this file.

LaunchDarkly intends to keep those versions up-to-date with the Go project's latest two releases, which represents a support period of roughly 1 year. This policy is intended to match Go's official Release Policy: each major Go release is supported until there are two newer major releases.

Additionally, a 'minimum' version is tested in CI but not officially supported. This minimum version is found in go.mod. This version may be bumped from time to time as new Go features become available that are useful to the SDK.

Installation

go get github.com/launchdarkly/eventsource

Documentation

License

Eventsource is available under the Apache License, Version 2.0.

# Functions

DecoderOptionLastEventID returns an option that sets the last event ID property for a Decoder when the Decoder is created.
DecoderOptionReadTimeout returns an option that sets the read timeout interval for a Decoder when the Decoder is created.
NewDecoder returns a new Decoder instance that reads events with the given io.Reader.
NewDecoderWithOptions returns a new Decoder instance that reads events with the given io.Reader, with optional configuration parameters.
NewEncoder returns an Encoder for a given io.Writer.
NewServer creates a new Server instance.
NewSliceRepository creates a SliceRepository.
StreamOptionCanRetryFirstConnection returns an option that determines whether to apply retry behavior to the first connection attempt for the stream.
StreamOptionDynamicQueryParams returns an option that sets a function to generate query parameters each time the stream needs to make a fresh connection.
StreamOptionErrorHandler returns an option that causes a Stream to call the specified function for stream errors.
StreamOptionHTTPClient returns an option that overrides the default HTTP client used by a stream when the stream is created.
StreamOptionInitialRetry returns an option that sets the initial retry delay for a stream when the stream is created.
StreamOptionLastEventID returns an option that sets the initial last event ID for a stream when the stream is created.
StreamOptionLogger returns an option that sets the logger for a stream when the stream is created (to change it later, you can use SetLogger).
StreamOptionReadTimeout returns an option that sets the read timeout interval for a stream when the stream is created.
StreamOptionRetryResetInterval returns an option that sets the minimum amount of time that a connection must stay open before the Stream resets its backoff delay.
StreamOptionUseBackoff returns an option that determines whether to use an exponential backoff for reconnection delays.
StreamOptionUseJitter returns an option that determines whether to use a randomized jitter for reconnection delays.
Subscribe to the Events emitted from the specified url.
SubscribeWith takes a HTTP client and request providing customization over both headers and control over the HTTP client settings (timeouts, tls, etc) If request.Body is set, then request.GetBody should also be set so that we can reissue the request Deprecated: use SubscribeWithRequestAndOptions instead.
SubscribeWithRequest will take an http.Request to set up the stream, allowing custom headers to be specified, authentication to be configured, etc.
SubscribeWithRequestAndOptions takes an initial http.Request to set up the stream - allowing custom headers, authentication, etc.
SubscribeWithURL subscribes to the Events emitted from the specified URL.

# Constants

DefaultInitialRetry is the default value for StreamOptionalInitialRetry.
DefaultRetryResetInterval is the default value for StreamOptionRetryResetInterval.

# Variables

ErrReadTimeout is the error that will be emitted if a stream was closed due to not receiving any data within the configured read timeout interval.

# Structs

A Decoder is capable of reading Events from a stream.
An Encoder is capable of writing Events to a stream.
Server manages any number of event-publishing channels and allows subscribers to consume them.
SliceRepository is an example repository that uses a slice as storage for past events.
Stream handles a connection for receiving Server Sent Events.
StreamErrorHandlerResult contains values returned by StreamErrorHandler.
SubscriptionError is an error object returned from a stream when there is an HTTP error.

# Interfaces

DecoderOption is a common interface for optional configuration parameters that can be used in creating a Decoder.
Event is the interface for any event received by the client or sent by the server.
EventWithLastID is an additional interface for an event received by the client, allowing access to the LastEventID method.
Logger is the interface for a custom logging implementation that can handle log output for a Stream.
Repository is an interface to be used with Server.Register() allowing clients to replay previous events through the server, if history is required.
StreamOption is a common interface for optional configuration parameters that can be used in creating a stream.

# Type aliases

StreamErrorHandler is a function type used with StreamOptionErrorHandler.