webhook

package
v1.2.12 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const MaxConsecutiveFailures = 10

MaxConsecutiveFailures is the threshold at which a webhook is auto-disabled.

Variables

ValidEventTypes is the set of all valid event type values for webhook subscriptions.

Functions

This section is empty.

Types

type Dispatcher

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

Dispatcher subscribes to SSE events and fans out to webhook subscriptions using the existing alert.Notifier worker pool.

func NewDispatcher

func NewDispatcher(store WebhookSubscriptionStore, notifier *alert.Notifier, logger *slog.Logger) *Dispatcher

NewDispatcher creates a new webhook dispatcher.

func (*Dispatcher) HandleEvent

func (d *Dispatcher) HandleEvent(ctx context.Context, eventType string, data interface{})

HandleEvent processes a single SSE event and dispatches to matching webhooks. Called from main.go when SSE events are broadcast.

type WebhookEvent

type WebhookEvent struct {
	Type      string      `json:"type"`
	Timestamp string      `json:"timestamp"`
	Data      interface{} `json:"data"`
}

WebhookEvent is the payload delivered to webhook URLs.

type WebhookSubscription

type WebhookSubscription struct {
	ID                 string     `json:"id"`
	Name               string     `json:"name"`
	URL                string     `json:"url"`
	Secret             string     `json:"secret,omitempty"`
	EventTypes         []string   `json:"event_types"`
	IsActive           bool       `json:"is_active"`
	LastDeliveryStatus *string    `json:"last_delivery_status"`
	LastDeliveryAt     *time.Time `json:"last_delivery_at"`
	FailureCount       int        `json:"failure_count"`
	CreatedAt          time.Time  `json:"created_at"`
}

WebhookSubscription represents a registered webhook URL.

type WebhookSubscriptionStore

type WebhookSubscriptionStore interface {
	List(ctx context.Context) ([]*WebhookSubscription, error)
	GetByID(ctx context.Context, id string) (*WebhookSubscription, error)
	Create(ctx context.Context, sub *WebhookSubscription) error
	Delete(ctx context.Context, id string) error
	UpdateDeliveryStatus(ctx context.Context, id string, status string, failureCount int) error
	ListActive(ctx context.Context) ([]*WebhookSubscription, error)
}

WebhookSubscriptionStore defines the persistence interface for webhook subscriptions.

Jump to

Keyboard shortcuts

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