webhook

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package webhook delivers events to registered HTTP endpoints.

Matching events are written to a durable queue (store.webhook_deliveries) before any network I/O, so deliveries survive restarts. Workers POST each event with an HMAC signature and retry failures with backoff.

Index

Constants

View Source
const (
	HeaderSignature = "X-Imsgd-Signature"
	HeaderEvent     = "X-Imsgd-Event"
	HeaderEventID   = "X-Imsgd-Event-Id"
	HeaderDelivery  = "X-Imsgd-Delivery"
)

Headers sent with each delivery.

Variables

View Source
var MaxAttempts = len(retryDelays) + 1

MaxAttempts is the number of attempts before a delivery is marked failed.

Functions

func Sign

func Sign(secret string, ts int64, body []byte) string

Sign computes the signature header value: "t=<unix>,v1=<hex HMAC-SHA256 of "<unix>.<body>" keyed with the secret>".

func Verify

func Verify(secret, header string, body []byte, now time.Time, tolerance time.Duration) error

Verify checks a signature header (for receivers written in Go, and tests). tolerance bounds the accepted clock skew / replay window.

Types

type Dispatcher

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

func New

func New(o Options) *Dispatcher

func (*Dispatcher) Invalidate

func (d *Dispatcher) Invalidate()

Invalidate reloads the webhook list on the next event (call after CRUD).

func (*Dispatcher) Run

func (d *Dispatcher) Run(ctx context.Context)

Run consumes events and delivers them until ctx is done.

func (*Dispatcher) SendTest

func (d *Dispatcher) SendTest(ctx context.Context, w *store.Webhook) TestResult

SendTest posts a webhook.test event to w immediately (not queued).

type Options

type Options struct {
	Store     *store.Store
	Bus       *events.Bus
	Version   string
	Client    *http.Client // default: 10s timeout
	Workers   int          // concurrent deliveries; default 4
	Retention time.Duration
	Now       func() time.Time
	// KeyExists reports whether an API key name is still configured;
	// webhooks owned by revoked keys are not delivered. Nil allows all.
	KeyExists func(name string) bool
}

type TestResult

type TestResult struct {
	OK         bool
	StatusCode int
	Error      string
	Duration   time.Duration
}

TestResult reports a synchronous test delivery.

Jump to

Keyboard shortcuts

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