Documentation ¶
Index ¶
- Constants
- func LogHook(db prefixer.Prefixer, hub Hub, parentDocType, documentID string) logrus.Hook
- type Doc
- type DynamicSubscriber
- func (ds *DynamicSubscriber) Close() error
- func (ds *DynamicSubscriber) Closed() bool
- func (ds *DynamicSubscriber) Subscribe(doctype string) error
- func (ds *DynamicSubscriber) Unsubscribe(doctype string) error
- func (ds *DynamicSubscriber) Unwatch(doctype, id string) error
- func (ds *DynamicSubscriber) Watch(doctype, id string) error
- type Event
- type Hub
- type JSONDoc
- type MemSub
Constants ¶
const ( EventCreate = "CREATED" EventUpdate = "UPDATED" EventDelete = "DELETED" EventNotify = "NOTIFIED" )
Basic data events
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DynamicSubscriber ¶
type DynamicSubscriber struct { prefixer.Prefixer Channel MemSub // contains filtered or unexported fields }
DynamicSubscriber is used to subscribe to several doctypes
func (*DynamicSubscriber) Close ¶
func (ds *DynamicSubscriber) Close() error
Close closes the channel (async)
func (*DynamicSubscriber) Closed ¶
func (ds *DynamicSubscriber) Closed() bool
Closed returns true if it will no longer send events in its channel
func (*DynamicSubscriber) Subscribe ¶
func (ds *DynamicSubscriber) Subscribe(doctype string) error
Subscribe adds a listener for events on a whole doctype
func (*DynamicSubscriber) Unsubscribe ¶
func (ds *DynamicSubscriber) Unsubscribe(doctype string) error
Unsubscribe removes a listener for events on a whole doctype
func (*DynamicSubscriber) Unwatch ¶
func (ds *DynamicSubscriber) Unwatch(doctype, id string) error
Unwatch removes a listener for events for a specific document (doctype+id)
func (*DynamicSubscriber) Watch ¶
func (ds *DynamicSubscriber) Watch(doctype, id string) error
Watch adds a listener for events for a specific document (doctype+id)
type Event ¶
type Event struct { Domain string `json:"domain"` Prefix string `json:"prefix,omitempty"` Verb string `json:"verb"` Doc Doc `json:"doc"` OldDoc Doc `json:"old,omitempty"` }
Event is the basic message structure manipulated by the realtime package
func (*Event) DomainName ¶
DomainName implements the prefixer.Prefixer interface.
type Hub ¶
type Hub interface { // Emit is used by publishers when an event occurs Publish(db prefixer.Prefixer, verb string, doc Doc, oldDoc Doc) // Subscriber creates a DynamicSubscriber that can subscribe to several // doctypes. Call its Close method to Unsubscribe. Subscriber(prefixer.Prefixer) *DynamicSubscriber // SubscribeLocalAll adds a listener for all events that happened in this // cozy-stack process. SubscribeLocalAll() *DynamicSubscriber // GetTopic returns the topic for the given domain+doctype. // It creates the topic if it does not exist. GetTopic(db prefixer.Prefixer, doctype string) *topic }
Hub is an object which recive events and calls appropriate listener
type JSONDoc ¶
JSONDoc is a map representing a simple json object that implements the couchdb.Doc interface.
Note: we can't use the couchdb.JSONDoc as the couchdb package imports the realtime package, and it would create an import loop. And we cannot move the JSONDoc from couchdb here, as some of its methods use other functions from the couchdb package.
func (*JSONDoc) MarshalJSON ¶
MarshalJSON is used for marshalling the document to JSON, with the doctype as _type.