Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
A Hub allows subscribers to receive notifications.
func (*Hub) Publish ¶
func (h *Hub) Publish(n *Notification)
Publish broadcasts a notification to subscribers.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(s *Subscriber)
Subscribe registers a subscriber to receive notifications.
func (*Hub) SubscriberCount ¶
SubscriberCount returns the number of subscribers
func (*Hub) Unsubscribe ¶
func (h *Hub) Unsubscribe(s *Subscriber)
Unsubscribe unregisters a subscriber from notifications.
type Notification ¶
type Notification struct { Timestamp int64 `json:"timestamp"` Type string `json:"type"` Resource string `json:"resource"` Metadata map[string]interface{} `json:"metadata"` }
A Notification is an event a subscriber is interested in knowing about.
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
A Subscriber is interested in receiving notifications
func NewSubscriber ¶
func NewSubscriber(c websocketConnection, r *http.Request) *Subscriber
NewSubscriber returns a new subscriber containing the given websocket connection and type/resource filters set from the query string params in the supplied http request
func (*Subscriber) Notify ¶
func (s *Subscriber) Notify(n *Notification) error
Notify receives a notification and if the subscriber is interested in it it is encoded as JSON and written to the websocket.
type Subscribers ¶
type Subscribers map[string]*Subscriber
Subscribers is a collection of subscribers