Documentation ¶
Index ¶
- Variables
- func Fire(ctx context.Context, id string, payload Data)
- func MatchSubscription(topic string, subscription string) bool
- func Subscribe(client, eventID string) <-chan *Event
- type Data
- type Event
- type Registry
- func (reg *Registry) Fire(ctx context.Context, id string, payload Data)
- func (reg *Registry) ListTypes() []Type
- func (reg *Registry) RegisterType(eventType Type) (*TypeRef, error)
- func (reg *Registry) Subscribe(client, eventID string) <-chan *Event
- func (reg *Registry) Unsubscribe(client, eventID string)
- type Type
- type TypeRef
Constants ¶
This section is empty.
Variables ¶
var DefaultRegistry = new(Registry)
DefaultRegistry is the event registry used by package level functions.
Functions ¶
func MatchSubscription ¶
MatchSubscription checks if topic matches the subscription. Topics are modelled after MQTT topics and are separated by using forward slashes. A '#' denotes a wildcard that matches the rest of the topic while '*' can be used as a wildcard that only matches the current field.
Types ¶
type Data ¶
type Data interface{}
Data is an opaque type for data attached to events fired by the event registry. The event data is not inspected by the registry but is likely used by any event subscribers. It's recommended that users make sure that the data attached to events is JSON serializable in case it's transmitted over network or file.
type Event ¶
type Event struct { // ID is the ID (or topic) of the event. The ID is used by // the registry to notify subscriptions that have a matching // topic filter. ID string `json:"id"` // Data is an opaque interface that is set to any // event data. Note that Data must not be modified after // the event has been fired or received on a subscription // channel. Callers of Fire() should make sure to send a // copy of their data if further manipulation is planned. // Subscribers many only perform read access as no synchronization // is in place. Data Data `json:"data"` // Created is set to the current time when calling Fire(). Created time.Time `json:"createdAt"` }
Event is an event emitted by a event registry and published to any subscriber.
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
func (*Registry) Subscribe ¶
Subscribe subscribes to events of the given eventID. All events fired on the registry that match the subscribed ID are published to the returned channel. Note that the order of events is not guaranteed.
func (*Registry) Unsubscribe ¶
Unsubscribe removes a previous subscription from client on eventID.