notifications

package
v1.0.0-beta.20 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetEventContent

func GetEventContent[EventType models.Events](raw *models.RawEvent) (*EventType, error)

GetEventContent returns the content of the raw event passed as a parameter.

func GetEventName

func GetEventName[EventType models.Events](instance *EventType) string

GetEventName returns the name of the event type passed as a parameter.

func GetEventNameByType

func GetEventNameByType[EventType models.Events]() string

GetEventNameByType returns the name of the event type passed as a type parameter.

func InstantinateEvent

func InstantinateEvent[EventType models.Events]() *EventType

InstantinateEvent creates a new instance of the event type passed as a type parameter.

func NewRawEvent

func NewRawEvent[EventType models.Events](namedEvent *EventType) *models.RawEvent

NewRawEvent creates a new raw event from actual event object.

func Notify

func Notify[EventType models.Events](n *Notifications, event *EventType)

Notify is a utility generc function which allows to push a new event to the notification system.

func StartSendingMockEvents

func StartSendingMockEvents[EventType models.Events](ctx context.Context, notificationService *Notifications, duration time.Duration, prepare func(i int) *EventType)

StartSendingMockEvents - utility function to start sending some events in a predefined interval. It's useful for testing

Types

type ModelWebhook

type ModelWebhook interface {
	GetURL() string
	GetTokenHeader() string
	GetTokenValue() string
	BanUntil(bannedTo time.Time)
	Refresh(tokenHeader, tokenValue string)
	Banned() bool
	Deleted() bool
}

ModelWebhook is an interface for a webhook model.

type Notifications

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

Notifications - service for sending events to multiple notifiers

func NewNotifications

func NewNotifications(ctx context.Context, parentLogger *zerolog.Logger) *Notifications

NewNotifications - creates a new instance of Notifications

func (*Notifications) AddNotifier

func (n *Notifications) AddNotifier(key string, ch chan *models.RawEvent)

AddNotifier - add notifier by key

func (*Notifications) Notify

func (n *Notifications) Notify(event *models.RawEvent)

Notify - send event to all notifiers

func (*Notifications) RemoveNotifier

func (n *Notifications) RemoveNotifier(key string)

RemoveNotifier - remove notifier by key

type WebhookManager

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

WebhookManager is a manager for webhooks. It is responsible for creating, updating and removing webhooks.

func NewWebhookManager

func NewWebhookManager(ctx context.Context, logger *zerolog.Logger, notifications *Notifications, repository WebhooksRepository) *WebhookManager

NewWebhookManager creates a new WebhookManager. It starts a goroutine which checks for webhook updates.

func (*WebhookManager) Stop

func (w *WebhookManager) Stop()

Stop stops the WebhookManager.

func (*WebhookManager) Subscribe

func (w *WebhookManager) Subscribe(ctx context.Context, url, tokenHeader, tokenValue string) error

Subscribe subscribes to a webhook. It adds the webhook to the database and starts a notifier for it.

func (*WebhookManager) Unsubscribe

func (w *WebhookManager) Unsubscribe(ctx context.Context, url string) error

Unsubscribe unsubscribes from a webhook. It removes the webhook from the database and stops the notifier for it.

type WebhookNotifier

type WebhookNotifier struct {
	Channel chan *models.RawEvent
	// contains filtered or unexported fields
}

WebhookNotifier - notifier for sending events to webhook

func NewWebhookNotifier

func NewWebhookNotifier(ctx context.Context, logger *zerolog.Logger, model ModelWebhook, banMsg chan string) *WebhookNotifier

NewWebhookNotifier - creates a new instance of WebhookNotifier

func (*WebhookNotifier) Update

func (w *WebhookNotifier) Update(model ModelWebhook)

Update - updates the webhook model

type WebhooksRepository

type WebhooksRepository interface {
	Create(ctx context.Context, url, tokenHeader, tokenValue string) error
	Save(ctx context.Context, model ModelWebhook) error
	Delete(ctx context.Context, model ModelWebhook) error
	GetAll(ctx context.Context) ([]ModelWebhook, error)
	GetByURL(ctx context.Context, url string) (ModelWebhook, error)
}

WebhooksRepository is an interface for managing webhooks.

Jump to

Keyboard shortcuts

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