webhook

package
v1.10.0 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("webhook not found")

ErrNotFound is returned when a webhook config does not exist.

Functions

func FormatGeneric

func FormatGeneric(event string, payload any) ([]byte, error)

FormatGeneric wraps the incident in a simple envelope and marshals it to JSON.

func FormatPagerDuty

func FormatPagerDuty(event string, payload any) ([]byte, error)

FormatPagerDuty formats an incident event as a PagerDuty Events API v2 payload.

func FormatSlack

func FormatSlack(event string, payload any) ([]byte, error)

FormatSlack formats an incident event as a Slack incoming-webhook payload.

Types

type Config

type Config struct {
	ID      string            `json:"id"`
	URL     string            `json:"url"`
	Type    string            `json:"type"`   // "slack", "pagerduty", "generic"
	Events  []string          `json:"events"` // "incident.created", "incident.resolved"
	Headers map[string]string `json:"headers,omitempty"`
	Active  bool              `json:"active"`
}

Config holds the configuration for a single outbound webhook.

type Dispatcher

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

Dispatcher fires outbound HTTP webhooks for incident events.

func NewDispatcher

func NewDispatcher(store Store) *Dispatcher

NewDispatcher creates a Dispatcher backed by the given store. A default HTTP client with a 10-second timeout is used.

func (*Dispatcher) Fire

func (d *Dispatcher) Fire(ctx context.Context, event string, payload any) error

Fire sends the payload to all active webhooks registered for the given event. It queries the store for matching configs, formats the payload per webhook type, and POSTs to each URL. Errors are logged but do not fail the caller (best-effort delivery).

func (*Dispatcher) FireToConfig

func (d *Dispatcher) FireToConfig(ctx context.Context, cfg Config, event string, payload any) error

FireToConfig sends a payload directly to a single webhook config, bypassing the store lookup. Useful for test deliveries.

func (*Dispatcher) Store

func (d *Dispatcher) Store() Store

Store returns the underlying webhook store.

type Store

type Store interface {
	Save(ctx context.Context, cfg *Config) error
	Get(ctx context.Context, id string) (*Config, error)
	List(ctx context.Context) ([]Config, error)
	Delete(ctx context.Context, id string) error
	ListByEvent(ctx context.Context, event string) ([]Config, error)
}

Store persists and retrieves webhook configs.

Directories

Path Synopsis
Package dynamostore implements webhook.Store backed by DynamoDB via the generic dynamostore package.
Package dynamostore implements webhook.Store backed by DynamoDB via the generic dynamostore package.

Jump to

Keyboard shortcuts

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