notifications

package
v0.0.0-...-677ed08 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2016 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	sync.Mutex
	// contains filtered or unexported fields
}

A Hub allows subscribers to receive notifications.

func NewHub

func NewHub() *Hub

NewHub returns an initialised hub

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

func (h *Hub) SubscriberCount() int

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL