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
- func AddressAllowed(ip net.IP, allowPrivate bool) bool
- func Body(w models.Webhook, d Delivery) ([]byte, error)
- func Configure(c Config)
- func Fanout(ctx context.Context, client queue.Client, ev events.CollectionEventPayload) error
- func HandleDelivery(ctx context.Context, payload []byte) error
- func NewSecret() string
- func Sign(secret, timestamp string, body []byte) string
- func ValidateHeaderName(name string) error
- func ValidateURL(raw string) error
- type BlockedAddressError
- type Config
- type Delivery
- type Result
Constants ¶
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 ¶
AddressAllowed reports whether a webhook may connect to ip.
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 ¶
HandleDelivery sends a queued delivery. Network errors, 5xx, 408 and 429 are retried with backoff; other 4xx answers are not.
func Sign ¶
Sign returns the X-Gohead-Signature value: HMAC-SHA256 of "<timestamp>.<body>" with the webhook's secret.
func ValidateHeaderName ¶
ValidateHeaderName rejects headers GoHead sets itself.
func ValidateURL ¶
ValidateURL checks a webhook URL's shape (addresses are checked at delivery time, after DNS resolution).
Types ¶
type BlockedAddressError ¶
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.