Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EmitOption ¶
type EmitOption func(*event)
EmitOption for being passed to an Emitter's Emit function mostly for altering the behavior or structure of the event
func WithName ¶
func WithName(name string) EmitOption
WithName is an EmitOption that sets the name for a given event to make it possible to make use of the addEventHandler on the EventSource in javascript
Emit("data", WithName("borg"))
source.addEventListener("borg", function(ev) { console.log("Oh no, the borg have ", ev.data) })
type Emitter ¶
type Emitter interface {
Emit(body interface{}, opts ...EmitOption)
}
Emitters Emit events with Optional arguments
type EventStream ¶
type EventStream struct {
// contains filtered or unexported fields
}
EventStream is your handy dandy all in one http.Handler and Emitter
func New ¶
func New(opts ...NewOption) *EventStream
New EventStream will construct a stream and start a goroutine to forward braodcast events in the background
func (*EventStream) Emit ¶
func (e *EventStream) Emit(body interface{}, opts ...EmitOption)
Emit an event
func (*EventStream) Len ¶
func (e *EventStream) Len() int
Len returns the number of connected clients
func (*EventStream) ServeHTTP ¶
func (e *EventStream) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements the http.Handler interface, requests will be handled if possible. It's this point where your onConnect callback will fire if you set it up.
type NewOption ¶
type NewOption func(*EventStream)
NewOption for being passed to the New() func
func WithOnConnect ¶
WithOnConnect allows you to pass an OnConnect function that will be passed an Emitter when a new client connects.