webhooks

package
v1.1.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2024 License: MIT Imports: 12 Imported by: 1

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 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.

Jump to

Keyboard shortcuts

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