webhooks

package
v2.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ScopeAll = "all"

	ScopeAlerts         = "alerts"
	ScopeAlertsInfo     = "alerts/info"
	ScopeAlertsWarning  = "alerts/warning"
	ScopeAlertsError    = "alerts/error"
	ScopeAlertsCritical = "alerts/critical"

	ScopeWallet = "wallet"
	ScopeTest   = "test"
)

event scope constants

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	ID    UID    `json:"id"`
	Event string `json:"event"`
	Scope string `json:"scope"`
	Data  any    `json:"data"`
}

An Event is a notification sent to a Webhook callback.

type Manager

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

A Manager manages Webhook subscribers and broadcasts events

func NewManager

func NewManager(store Store, log *zap.Logger) (*Manager, error)

NewManager creates a new Webhook Manager

func (*Manager) BroadcastEvent

func (m *Manager) BroadcastEvent(event string, scope string, data any) error

BroadcastEvent sends an event to all registered Webhooks that match the event's scope.

func (*Manager) BroadcastToWebhook

func (m *Manager) BroadcastToWebhook(hookID int64, event string, scope string, data any) error

BroadcastToWebhook sends an event to a specific Webhook subscriber.

func (*Manager) Close

func (m *Manager) Close() error

Close closes the Manager.

func (*Manager) RegisterWebhook

func (m *Manager) RegisterWebhook(url string, scopes []string) (Webhook, error)

RegisterWebhook registers a new Webhook.

func (*Manager) RemoveWebhook

func (m *Manager) RemoveWebhook(id int64) error

RemoveWebhook removes a registered Webhook.

func (*Manager) UpdateWebhook

func (m *Manager) UpdateWebhook(id int64, url string, scopes []string) (Webhook, error)

UpdateWebhook updates the URL and scopes of a registered Webhook.

func (*Manager) Webhooks

func (m *Manager) Webhooks() (hooks []Webhook, _ error)

Webhooks returns all registered Webhooks.

type NoOpBroadcaster

type NoOpBroadcaster struct{}

A NoOpBroadcaster is a WebhookBroadcaster that does nothing.

func NewNop

func NewNop() NoOpBroadcaster

NewNop returns a new NoOpBroadcaster.

func (NoOpBroadcaster) BroadcastEvent

func (NoOpBroadcaster) BroadcastEvent(event string, scope string, data any) error

BroadcastEvent implements WebhookBroadcaster.

func (NoOpBroadcaster) BroadcastToWebhook

func (NoOpBroadcaster) BroadcastToWebhook(hookID int64, event string, scope string, data any) error

BroadcastToWebhook implements WebhookBroadcaster.

type Store

type Store interface {
	RegisterWebhook(url, secret string, scopes []string) (int64, error)
	UpdateWebhook(id int64, url string, scopes []string) error
	RemoveWebhook(id int64) error
	Webhooks() ([]Webhook, error)
}

A Store stores and retrieves Webhooks.

type UID

type UID [32]byte

A UID is a unique identifier for an event.

type Webhook

type Webhook struct {
	ID          int64    `json:"id"`
	CallbackURL string   `json:"callbackURL"`
	SecretKey   string   `json:"secretKey"`
	Scopes      []string `json:"scopes"`
}

A Webhook is a callback that is invoked when an event occurs.

type WebhookBroadcaster

type WebhookBroadcaster interface {
	BroadcastEvent(event string, scope string, data any) error
	BroadcastToWebhook(hookID int64, event string, scope string, data any) error
}

A WebhookBroadcaster broadcasts events to webhooks.

Jump to

Keyboard shortcuts

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