events

package
v0.0.0-...-2e7266e Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2020 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AppNotification

type AppNotification struct {
	To        []models.User
	Title     string
	Body      string
	NotifType string
	Channel   string
}

AppNotification represents the data required to push a notification to a device using FCM

type Bus

type Bus interface {
	// Init is used to build a Bus by registering
	// multiple EventRoutes in it. It's like a constructor
	Init(BusConf, []EventRoute)
	// Register adds a new 'endpoint' to the bus
	Register(EventRoute)
	// Publish pushes a new event to the Bus
	Publish(string, Event)
}

Bus is an entity that can route events to different EventRoutes based on their topic

func MakeBus

func MakeBus(b BusConf) Bus

MakeBus will return a fully loaded (with EventRoutes) Bus. This function won't be dynamic, need to hardcode all the EventRoutes here.

type BusConf

type BusConf struct {
	Firebase firebaseConf
}

BusConf contains information needed by the Bus (passed using dependency injection)

func GetBusConf

func GetBusConf() BusConf

GetBusConf will return a BusConf built from the environment

type Event

type Event interface{}

Event contains information about the Topic of the event (used to determine where the event will be sent) and the data of the event

type EventBus

type EventBus struct {
	// contains filtered or unexported fields
}

EventBus will route events to appropriate handlers

func (*EventBus) Init

func (eb *EventBus) Init(b BusConf, routes []EventRoute)

Init should be used to initialize the EventBus with EventRoutes by repeatedly calling Register()

func (*EventBus) Publish

func (eb *EventBus) Publish(topic string, ed Event)

Publish takes an event and routes it to the appropriate route

func (*EventBus) Register

func (eb *EventBus) Register(er EventRoute)

Register will register a route in the EventBus

type EventChan

type EventChan chan Event

EventChan is a channel for the Event data type

type EventRoute

type EventRoute interface {
	// Init is used for any initial setup of the EventRoute
	Init(interface{})

	// Topic returns the topic of the EventRoute
	Topic() interface{}

	// Consume spawns a goroutine for every worker to work
	// on the event
	Consume(Event)

	// RegisterWorker registers a worker function to consume
	// any incoming events in this EventRoute
	RegisterWorker(Worker)
}

EventRoute is an entity that can consume events by passing them to several registered workers

func HSCuredRoute

func HSCuredRoute(b BusConf) EventRoute

HSCuredRoute will handle all events of a patient being cured

func HSDiedRoute

func HSDiedRoute(b BusConf) EventRoute

HSDiedRoute will handle all events of a patient dying

func HSFeelingSymptomsRoute

func HSFeelingSymptomsRoute(b BusConf) EventRoute

HSFeelingSymptomsRoute will handle all events of a patient starting to feel symptoms

func HSPositiveRoute

func HSPositiveRoute(b BusConf) EventRoute

HSPositiveRoute will handle all events of a patient being tested positive

func UsersMetRoute

func UsersMetRoute(b BusConf) EventRoute

UsersMetRoute will get all the events related to meeting users who were feeling symptoms or have been tested positive

type GooglePubSubClient

type GooglePubSubClient struct {
	// contains filtered or unexported fields
}

GooglePubSubClient stores data required to push messages to Google PubSub

func (*GooglePubSubClient) Init

func (gpsc *GooglePubSubClient) Init(topics []string)

Init initializes the pubsub client with the underlying data it needs in order to publish messages

func (*GooglePubSubClient) Publish

func (gpsc *GooglePubSubClient) Publish(topicName string, data map[string]interface{})

Publish will publish a message to a given topic

type NativeEventRoute

type NativeEventRoute struct {
	// contains filtered or unexported fields
}

NativeEventRoute is used to pass events to functions native to this application

func (*NativeEventRoute) Consume

func (ner *NativeEventRoute) Consume(e Event)

Consume spawns a goroutine for every worker to work on the event

func (*NativeEventRoute) Init

func (ner *NativeEventRoute) Init(t interface{})

Init is used for any initial setup of the EventRoute

func (*NativeEventRoute) RegisterWorker

func (ner *NativeEventRoute) RegisterWorker(w Worker)

RegisterWorker registers a worker function to consume any incoming events in this EventRoute

func (*NativeEventRoute) Topic

func (ner *NativeEventRoute) Topic() interface{}

Topic returns the topic of the EventRoute

type PubSubAgent

type PubSubAgent interface {
	Init()
	Publish(string, interface{})
}

PubSubAgent represents an entity that can publish messages to some pubsub service like Google Pubsub

type UsersMetEvent

type UsersMetEvent struct {
	User1     models.User
	User2     models.User
	TimeSpent int64
}

UsersMetEvent is an event that stores information about a user meeting another user

type Worker

type Worker func(Event)

Worker is just a function with accepts an Event and does something with it

func AnalyseUsersMetEvent

func AnalyseUsersMetEvent(fcmKey string) Worker

func SendHSChangeNotificationWorker

func SendHSChangeNotificationWorker(fcmKey string) Worker

SendHSChangeNotificationWorker returns a Worker that will send a notification to a group of users using FCM

type WorkerList

type WorkerList []Worker

WorkerList is a slice of workers

Jump to

Keyboard shortcuts

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