sse: Index | Files

package sse

import ""


Package Files

client.go event.go event_log.go http.go server.go stream.go subscriber.go


const DefaultBufferSize = 1024

DefaultBufferSize size of the queue that holds the streams messages.

type Client Uses

type Client struct {
    URL        string
    Connection *http.Client
    Retry      time.Time

    Headers        map[string]string
    EncodingBase64 bool
    EventID        string

    ResponseValidator ResponseValidator
    ReconnectStrategy backoff.BackOff
    ReconnectNotify   backoff.Notify
    // contains filtered or unexported fields

Client handles an incoming server stream

func NewClient Uses

func NewClient(url string) *Client

NewClient creates a new client

func (*Client) OnDisconnect Uses

func (c *Client) OnDisconnect(fn ConnCallback)

OnDisconnect specifies the function to run when the connection disconnects

func (*Client) Subscribe Uses

func (c *Client) Subscribe(stream string, handler func(msg *Event)) error

Subscribe to a data stream

func (*Client) SubscribeChan Uses

func (c *Client) SubscribeChan(stream string, ch chan *Event) error

SubscribeChan sends all events to the provided channel

func (*Client) SubscribeChanRaw Uses

func (c *Client) SubscribeChanRaw(ch chan *Event) error

SubscribeChanRaw sends all events to the provided channel

func (*Client) SubscribeChanRawWithContext Uses

func (c *Client) SubscribeChanRawWithContext(ctx context.Context, ch chan *Event) error

SubscribeChanRawWithContext sends all events to the provided channel with context

func (*Client) SubscribeChanWithContext Uses

func (c *Client) SubscribeChanWithContext(ctx context.Context, stream string, ch chan *Event) error

SubscribeChanWithContext sends all events to the provided channel with context

func (*Client) SubscribeRaw Uses

func (c *Client) SubscribeRaw(handler func(msg *Event)) error

SubscribeRaw to an sse endpoint

func (*Client) SubscribeRawWithContext Uses

func (c *Client) SubscribeRawWithContext(ctx context.Context, handler func(msg *Event)) error

SubscribeRawWithContext to an sse endpoint with context

func (*Client) SubscribeWithContext Uses

func (c *Client) SubscribeWithContext(ctx context.Context, stream string, handler func(msg *Event)) error

SubscribeWithContext to a data stream with context

func (*Client) Unsubscribe Uses

func (c *Client) Unsubscribe(ch chan *Event)

Unsubscribe unsubscribes a channel

type ConnCallback Uses

type ConnCallback func(c *Client)

ConnCallback defines a function to be called on a particular connection event

type Event Uses

type Event struct {
    ID    []byte
    Data  []byte
    Event []byte
    Retry []byte
    // contains filtered or unexported fields

Event holds all of the event source fields

type EventLog Uses

type EventLog []*Event

EventLog holds all of previous events

func (*EventLog) Add Uses

func (e *EventLog) Add(ev *Event)

Add event to eventlog

func (*EventLog) Clear Uses

func (e *EventLog) Clear()

Clear events from eventlog

func (*EventLog) Replay Uses

func (e *EventLog) Replay(s *Subscriber)

Replay events to a subscriber

type EventStreamReader Uses

type EventStreamReader struct {
    // contains filtered or unexported fields

EventStreamReader scans an io.Reader looking for EventStream messages.

func NewEventStreamReader Uses

func NewEventStreamReader(eventStream io.Reader) *EventStreamReader

NewEventStreamReader creates an instance of EventStreamReader.

func (*EventStreamReader) ReadEvent Uses

func (e *EventStreamReader) ReadEvent() ([]byte, error)

ReadEvent scans the EventStream for events.

type ResponseValidator Uses

type ResponseValidator func(c *Client, resp *http.Response) error

type Server Uses

type Server struct {
    // Specifies the size of the message buffer for each stream
    BufferSize int
    // Enables creation of a stream when a client connects
    AutoStream bool
    // Enables automatic replay for each new subscriber that connects
    AutoReplay bool
    // Encodes all data as base64
    EncodeBase64 bool
    // Sets a ttl that prevents old events from being transmitted
    EventTTL time.Duration
    Streams  map[string]*Stream
    Headers  map[string]string
    // contains filtered or unexported fields

Server Is our main struct

func New Uses

func New() *Server

New will create a server and setup defaults

func (*Server) Close Uses

func (s *Server) Close()

Close shuts down the server, closes all of the streams and connections

func (*Server) CreateStream Uses

func (s *Server) CreateStream(id string) *Stream

CreateStream will create a new stream and register it

func (*Server) HTTPHandler Uses

func (s *Server) HTTPHandler(w http.ResponseWriter, r *http.Request)

HTTPHandler serves new connections with events for a given stream ...

func (*Server) Publish Uses

func (s *Server) Publish(id string, event *Event)

Publish sends a mesage to every client in a streamID

func (*Server) RemoveStream Uses

func (s *Server) RemoveStream(id string)

RemoveStream will remove a stream

func (*Server) StreamExists Uses

func (s *Server) StreamExists(id string) bool

StreamExists checks whether a stream by a given id exists

type Stream Uses

type Stream struct {
    // Enables replaying of eventlog to newly added subscribers
    AutoReplay bool
    Eventlog   EventLog
    // contains filtered or unexported fields

Stream ...

type StreamRegistration Uses

type StreamRegistration struct {
    // contains filtered or unexported fields

StreamRegistration ...

type Subscriber Uses

type Subscriber struct {
    // contains filtered or unexported fields

Subscriber ...

Package sse imports 12 packages (graph) and is imported by 27 packages. Updated 2020-10-07. Refresh now. Tools for package owners.