Help us shape the future of Go! Take the 2026 Go Developer Survey

webhooks

package
v0.16.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Overview

Package webhooks sends signed HTTP notifications of site events (content, media, menus, forms, sign-ins, orders, migrations) to subscribed endpoints, with retries, a delivery log, redelivery and secret rotation.

Index

Constants

View Source
const Perm = "webhooks.manage"

Perm is the permission for managing webhooks.

View Source
const TestEvent = "webhook.test"

TestEvent is sent by Test; webhooks need not subscribe to it.

Variables

View Source
var (
	// ErrNotFound is returned for an unknown webhook or delivery.
	ErrNotFound = errors.New("webhooks: not found")
	// ErrInactive is returned when testing or redelivering to a disabled webhook.
	ErrInactive = errors.New("webhooks: webhook is disabled")
)

Functions

func RedactURL

func RedactURL(raw string) string

RedactURL returns raw as origin + path, with "?…" in place of any query string: endpoints often carry a token there. Lists, the audit log and list API responses show this form; storage and the edit views keep the full URL. An unparsable URL redacts to "".

func Sign

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

Sign returns the X-GoRun-Signature value for body sent at timestamp ts: "sha256=" + hex(HMAC-SHA256(secret, ts + "." + body)).

func Verify

func Verify(secret, signature string, ts int64, body []byte, now time.Time, tolerance time.Duration) bool

Verify checks a signature header against body, rejecting timestamps older than tolerance (receivers can use it; it is also the reference for docs).

Types

type CreateResponse

type CreateResponse struct {
	Webhook Webhook `json:"webhook"`
	Secret  string  `json:"secret" doc:"whsec_…; sign check: sha256=hex(HMAC-SHA256(secret, timestamp + \".\" + body))"`
}

CreateResponse is returned once by POST /v1/webhooks and POST /v1/webhooks/{id}/secret: secret is never shown again.

type DeleteResponse

type DeleteResponse struct {
	ID      string `json:"id"`
	Deleted bool   `json:"deleted"`
}

DeleteResponse is returned by DELETE /v1/webhooks/{id}.

type Delivery

type Delivery struct {
	ID           string `json:"id"`
	WebhookID    string `json:"webhook_id"`
	Event        string `json:"event"`
	Status       string `json:"status" doc:"queued | delivered | retrying | failed"`
	Attempts     int    `json:"attempts"`
	ResponseCode int    `json:"response_code"`
	Error        string `json:"error"`
	DurationMS   int    `json:"duration_ms"`
	CreatedAt    string `json:"created_at"`
	DeliveredAt  string `json:"delivered_at"`
	Payload      string `json:"payload,omitempty" doc:"the signed JSON body; returned by the deliveries list"`
}

Delivery is one event sent (or being retried) to one webhook.

type Event

type Event struct {
	Name  string            `json:"name"`
	Label map[string]string `json:"label"`
}

Event is a site event a webhook can subscribe to.

func Events

func Events() []Event

Events returns the subscribable events.

type Input

type Input struct {
	Name   *string  `json:"name,omitempty"`
	URL    *string  `json:"url,omitempty"`
	Events []string `json:"events,omitempty"`
	Active *bool    `json:"active,omitempty"`
}

Input is the writable state of a webhook (create, or update: nil fields keep).

type Module

type Module struct{}

Module is the webhooks kernel.Module.

func New

func New() *Module

New returns the webhooks module.

func (*Module) Catalogs

func (*Module) Catalogs() fs.FS

Catalogs implements kernel.CatalogProvider.

func (*Module) Migrations

func (*Module) Migrations() fs.FS

Migrations implements kernel.Module.

func (*Module) Name

func (*Module) Name() string

Name implements kernel.Module.

func (*Module) Register

func (*Module) Register(d *kernel.Deps) error

Register publishes the service, subscribes to every catalog event, registers the delivery job and the daily prune, and adds the admin screens and API operations.

type Service

type Service interface {
	List(ctx context.Context) ([]Webhook, error)
	Get(ctx context.Context, id string) (*Webhook, error)
	Create(ctx context.Context, in Input) (*Webhook, string, error)
	Update(ctx context.Context, id string, in Input) (*Webhook, error)
	Delete(ctx context.Context, id string) error
	RotateSecret(ctx context.Context, id string) (string, error)
	Test(ctx context.Context, id string) (*Delivery, error)
	Deliveries(ctx context.Context, webhookID string, limit int) ([]Delivery, error)
	Redeliver(ctx context.Context, deliveryID string) (*Delivery, error)
}

Service manages webhooks (kernel.ServiceWebhooks).

type ValidationError

type ValidationError struct{ Fields map[string]string }

ValidationError lists invalid fields as i18n keys.

func (*ValidationError) Error

func (e *ValidationError) Error() string

type Webhook

type Webhook struct {
	ID                  string   `json:"id"`
	Name                string   `json:"name"`
	URL                 string   `json:"url" doc:"lists show origin and path only (query as ?…); get returns the full URL"`
	Events              []string `json:"events" doc:"event names, or [\"*\"] for every event"`
	Active              bool     `json:"active"`
	ConsecutiveFailures int      `json:"consecutive_failures"`
	LastStatus          string   `json:"last_status" doc:"\"\" | delivered | retrying | failed"`
	LastDeliveryAt      string   `json:"last_delivery_at"`
	CreatedAt           string   `json:"created_at"`
	UpdatedAt           string   `json:"updated_at"`
}

Webhook is an endpoint subscribed to site events.

func Redacted

func Redacted(list []Webhook) []Webhook

Redacted returns a copy of list with every URL passed through RedactURL.

Jump to

Keyboard shortcuts

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