Documentation
¶
Index ¶
- func GetEventContent[EventType models.Events](raw *models.RawEvent) (*EventType, error)
- func GetEventName[EventType models.Events](instance *EventType) string
- func GetEventNameByType[EventType models.Events]() string
- func InstantinateEvent[EventType models.Events]() *EventType
- func NewRawEvent[EventType models.Events](namedEvent *EventType) *models.RawEvent
- func Notify[EventType models.Events](n *Notifications, event *EventType)
- func StartSendingMockEvents[EventType models.Events](ctx context.Context, notificationService *Notifications, ...)
- type ModelWebhook
- type Notifications
- type WebhookManager
- type WebhookNotifier
- type WebhooksRepository
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetEventContent ¶
GetEventContent returns the content of the raw event passed as a parameter.
func GetEventName ¶
GetEventName returns the name of the event type passed as a parameter.
func GetEventNameByType ¶
GetEventNameByType returns the name of the event type passed as a type parameter.
func InstantinateEvent ¶
InstantinateEvent creates a new instance of the event type passed as a type parameter.
func NewRawEvent ¶
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) Close ¶ added in v1.1.0
func (n *Notifications) Close() error
Close - stops the notification service and cleans up resources
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) GetAll ¶
func (w *WebhookManager) GetAll(ctx context.Context) ([]ModelWebhook, error)
GetAll returns all the webhooks stored in database
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) Stop ¶ added in v1.1.0
func (w *WebhookNotifier) Stop()
Stop - stops the webhook notifier and waits for the consumer goroutine to finish. IMPORTANT: Callers should remove this notifier from Notifications before calling Stop, and should cancel the context before calling Stop to ensure prompt shutdown.
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.