webhooks

package
v0.6.3 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2026 License: MIT Imports: 22 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 webhooks delivers content events to external URLs. The event dispatcher fans each event out into one queued delivery per subscribed webhook; workers send them, signed, with retries and a delivery log.

Index

Constants

View Source
const (
	// TaskTypeDeliver is the queued task that sends one event to one webhook.
	TaskTypeDeliver = "webhook:deliver"
	// Queue is the queue deliveries go through (served by `gohead worker`).
	Queue = "webhooks"
	// EventTest is the event sent by the "test" endpoint.
	EventTest = "webhook:test"
)

Variables

This section is empty.

Functions

func AddressAllowed

func AddressAllowed(ip net.IP, allowPrivate bool) bool

AddressAllowed reports whether a webhook may connect to ip.

func Body

func Body(w models.Webhook, d Delivery) ([]byte, error)

Body renders the request body for the webhook's format.

func Configure

func Configure(c Config)

Configure sets the delivery settings (call at startup).

func Fanout

Fanout enqueues one delivery per webhook subscribed to the event. The task IDs derive from the event task's ID, so a retried event does not deliver twice.

func HandleDelivery

func HandleDelivery(ctx context.Context, payload []byte) error

HandleDelivery sends a queued delivery. Network errors, 5xx, 408 and 429 are retried with backoff; other 4xx answers are not.

func NewSecret

func NewSecret() string

NewSecret returns a random signing secret.

func Sign

func Sign(secret, timestamp string, body []byte) string

Sign returns the X-Gohead-Signature value: HMAC-SHA256 of "<timestamp>.<body>" with the webhook's secret.

func ValidateHeaderName

func ValidateHeaderName(name string) error

ValidateHeaderName rejects headers GoHead sets itself.

func ValidateURL

func ValidateURL(raw string) error

ValidateURL checks a webhook URL's shape (addresses are checked at delivery time, after DNS resolution).

Types

type BlockedAddressError

type BlockedAddressError struct{ IP net.IP }

BlockedAddressError is returned when a webhook resolves to an address it may not reach.

func (*BlockedAddressError) Error

func (e *BlockedAddressError) Error() string

type Config

type Config struct {
	// AllowPrivateNetworks lets webhooks reach private and loopback
	// addresses (internal rebuild hooks, local development). Link-local
	// addresses (cloud metadata endpoints) are always refused.
	AllowPrivateNetworks bool
	Timeout              time.Duration
	MaxRetries           int
}

Config controls deliveries.

type Delivery

type Delivery struct {
	WebhookID  uint           `json:"webhook_id"`
	DeliveryID string         `json:"delivery_id"`
	Event      string         `json:"event"`
	Collection string         `json:"collection"`
	ItemID     uint           `json:"item_id"`
	Item       map[string]any `json:"item"`
	// Translations: the item's localized values in other locales.
	Translations map[string]any `json:"translations,omitempty"`
	OccurredAt   time.Time      `json:"occurred_at"`
}

Delivery is the payload of a queued delivery.

type Result

type Result struct {
	StatusCode int
	Duration   time.Duration
	Err        error
	Permanent  bool // retrying will not help
}

Result describes one attempt.

func Send

func Send(ctx context.Context, w models.Webhook, d Delivery, attempt int) Result

Send delivers d to w now, records the attempt and returns its outcome.

Jump to

Keyboard shortcuts

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