Documentation
¶
Overview ¶
Eventsource package provides the utilities to connect and process events from an HTML5 Server-Sent Events endpoint.
Index ¶
Constants ¶
const (
ContentType = "text/event-stream"
)
Variables ¶
var ( // ErrContentType means the content-type header of the server is not the // expected one for an event-source. EventSource always expects // `text/event-stream`. content-type. ErrContentType = errors.New("eventsource: the content type of the stream is not allowed") // status code. ErrUnauthorized = errors.New("eventsource: connection is unauthorized") )
Functions ¶
This section is empty.
Types ¶
type EventSource ¶
type EventSource struct {
// contains filtered or unexported fields
}
EventSource connects and processes events from an HTTP server-sent events stream.
func New ¶
func New(url string, requestModifiers ...RequestModifier) (*EventSource, error)
New EventSource, it accepts requests modifiers which allow to modify the underlying HTTP request, see RequestModifier.
func (*EventSource) Close ¶
func (es *EventSource) Close()
Close the event source. Once it has been closed, the event source cannot be re-used again.
func (*EventSource) MessageEvents ¶
func (es *EventSource) MessageEvents() <-chan *base.MessageEvent
MessageEvents returns a receive-only channel where events are received.
func (*EventSource) ReadyState ¶
func (es *EventSource) ReadyState() <-chan Status
ReadyState exposes a channel with updates on the ready state of the EventSource. It must be consumed together with MessageEvents.
type ReadyState ¶
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 // Closed after the connection is closed. Closed )
func (ReadyState) String ¶
func (i ReadyState) String() string
type RequestModifier ¶
RequestModifier function for modifying the HTTP connection request.
func WithBasicAuth ¶
func WithBasicAuth(username, password string) RequestModifier
WithBasicAuth adds basic authentication to the HTTP request
func WithBearerTokenAuth ¶
func WithBearerTokenAuth(token string) RequestModifier
WithBearerTokenAuth adds bearer token header to the HTTP request
type Status ¶
type Status struct { Err error ReadyState ReadyState }
Status groups together a ready state and possible error associated with it. Useful to notify changes and why they happened.