webhook

package
v0.35.6 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: GPL-3.0 Imports: 17 Imported by: 1 module, 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 the events of a subscription as signed HTTP POSTs.

Delivery is at least once and in order, from one goroutine: while an event is being retried the later ones wait in the subscription's bounded queue, and what does not fit there is dropped by the hub. Receivers de-duplicate by the event id, which stays the same across retries.

Index

Constants

View Source
const (
	HeaderEventID   = "X-NPS-Event-Id"
	HeaderEventType = "X-NPS-Event-Type"
	HeaderTimestamp = "X-NPS-Timestamp"
	HeaderSignature = "X-NPS-Signature"
)

The headers of a delivery.

Variables

This section is empty.

Functions

func Sign

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

Sign returns the value of HeaderSignature for a body sent at timestamp: "sha256=" and the hex HMAC-SHA256 of "<timestamp>.<body>".

Types

type Config

type Config struct {
	URL string
	// Secret signs the deliveries; if empty they carry no signature.
	Secret string
	// Timeout bounds one attempt; zero or less means 5 seconds.
	Timeout time.Duration
	// Retries is how many times a failed attempt is repeated; zero or less
	// means none.
	Retries int
	// Backoff is the wait before the first retry, doubling up to 30 seconds;
	// zero or less means a second.
	Backoff time.Duration
}

Config configures a Sender.

type Sender

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

Sender delivers the events of one subscription.

func Start

func Start(cfg Config, sub *event.Subscription) *Sender

Start begins delivering what sub receives. The Sender owns sub.

func (*Sender) Close

func (s *Sender) Close()

Close stops at once: an attempt in flight is cancelled and queued events are discarded. Deliveries are not persisted, so they do not survive it.

func (*Sender) Delivered

func (s *Sender) Delivered() uint64

Delivered returns how many events a receiver accepted.

func (*Sender) Failed

func (s *Sender) Failed() uint64

Failed returns how many events were given up on.

Jump to

Keyboard shortcuts

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