Documentation ¶
Index ¶
- Constants
- type Client
- func (c *Client) OnDisconnect(fn ConnCallback)
- func (c *Client) Subscribe(stream string, handler func(msg *Event)) error
- func (c *Client) SubscribeChan(stream string, ch chan *Event) error
- func (c *Client) SubscribeChanRaw(ch chan *Event) error
- func (c *Client) SubscribeChanRawWithContext(ctx context.Context, ch chan *Event) error
- func (c *Client) SubscribeChanWithContext(ctx context.Context, stream string, ch chan *Event) error
- func (c *Client) SubscribeRaw(handler func(msg *Event)) error
- func (c *Client) SubscribeRawWithContext(ctx context.Context, handler func(msg *Event)) error
- func (c *Client) SubscribeWithContext(ctx context.Context, stream string, handler func(msg *Event)) error
- func (c *Client) Unsubscribe(ch chan *Event)
- type ConnCallback
- type Event
- type EventLog
- type EventStreamReader
- type Server
- type Stream
- type StreamRegistration
- type Subscriber
Constants ¶
const DefaultBufferSize = 1024
DefaultBufferSize size of the queue that holds the streams messages.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct { URL string Connection *http.Client Retry time.Time Headers map[string]string EncodingBase64 bool EventID string ReconnectStrategy backoff.BackOff // contains filtered or unexported fields }
Client handles an incoming server stream
func (*Client) OnDisconnect ¶
func (c *Client) OnDisconnect(fn ConnCallback)
OnDisconnect specifies the function to run when the connection disconnects
func (*Client) SubscribeChan ¶
SubscribeChan sends all events to the provided channel
func (*Client) SubscribeChanRaw ¶
SubscribeChanRaw sends all events to the provided channel
func (*Client) SubscribeChanRawWithContext ¶
SubscribeChanRawWithContext sends all events to the provided channel with context
func (*Client) SubscribeChanWithContext ¶
SubscribeChanWithContext sends all events to the provided channel with context
func (*Client) SubscribeRaw ¶
SubscribeRaw to an sse endpoint
func (*Client) SubscribeRawWithContext ¶
SubscribeRawWithContext to an sse endpoint with context
func (*Client) SubscribeWithContext ¶
func (c *Client) SubscribeWithContext(ctx context.Context, stream string, handler func(msg *Event)) error
SubscribeWithContext to a data stream with context
func (*Client) Unsubscribe ¶
Unsubscribe unsubscribes a channel
type ConnCallback ¶
type ConnCallback func(c *Client)
ConnCallback defines a function to be called on a particular connection event
type Event ¶
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 EventStreamReader ¶
type EventStreamReader struct {
// contains filtered or unexported fields
}
EventStreamReader scans an io.Reader looking for EventStream messages.
func NewEventStreamReader ¶
func NewEventStreamReader(eventStream io.Reader) *EventStreamReader
NewEventStreamReader creates an instance of EventStreamReader.
func (*EventStreamReader) ReadEvent ¶
func (e *EventStreamReader) ReadEvent() ([]byte, error)
ReadEvent scans the EventStream for events.
type Server ¶
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 (*Server) Close ¶
func (s *Server) Close()
Close shuts down the server, closes all of the streams and connections
func (*Server) CreateStream ¶
CreateStream will create a new stream and register it
func (*Server) HTTPHandler ¶
func (s *Server) HTTPHandler(w http.ResponseWriter, r *http.Request)
HTTPHandler serves new connections with events for a given stream ...
func (*Server) RemoveStream ¶
RemoveStream will remove a stream
func (*Server) StreamExists ¶
StreamExists checks whether a stream by a given id exists
type Stream ¶
type Stream struct { // Enables replaying of eventlog to newly added subscribers AutoReplay bool Eventlog EventLog // contains filtered or unexported fields }
Stream ...
type StreamRegistration ¶
type StreamRegistration struct {
// contains filtered or unexported fields
}
StreamRegistration ...
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscriber ...