webhook

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const SignatureHeaderName = "X-Webhook-Signature"

SignatureHeaderName is the header used for webhook signatures.

Variables

View Source
var (
	ErrInvalidSignature = errors.New("invalid webhook signature")
	ErrMissingSignature = errors.New("missing webhook signature header")
)

Signature verification errors.

Functions

func GetDeliveryID

func GetDeliveryID(req *http.Request) string

GetDeliveryID extracts the delivery ID from the request header.

func GetEventType

func GetEventType(req *http.Request) string

GetEventType extracts the event type from the request header.

func VerifyPayload

func VerifyPayload(payload []byte, signature string, secret string) error

VerifyPayload verifies a raw payload against a signature.

func VerifyRequest

func VerifyRequest(req *http.Request, payload []byte, secret string) error

VerifyRequest verifies the signature of an incoming webhook request.

func VerifySignature

func VerifySignature(payload []byte, signature string, secret string) bool

VerifySignature verifies that the webhook signature is valid.

Types

type Delivery

type Delivery struct {
	ID        string          `json:"id"`
	EventType string          `json:"event_type"`
	URL       string          `json:"url"`
	Payload   json.RawMessage `json:"payload"`
	Headers   http.Header     `json:"headers"`

	StatusCode int           `json:"status_code"`
	Response   string        `json:"response,omitempty"`
	Duration   time.Duration `json:"duration"`
	Success    bool          `json:"success"`
	Retries    int           `json:"retries"`
	CreatedAt  time.Time     `json:"created_at"`
	SentAt     *time.Time    `json:"sent_at,omitempty"`
}

Delivery represents a webhook delivery attempt.

type DeliveryConfig

type DeliveryConfig struct {
	Timeout       time.Duration `default:"30s"`
	MaxRetries    int           `default:"5"`
	RetryBackoff  time.Duration `default:"1s"`
	SignAlgorithm string        `default:"hmac-sha256"`
}

DeliveryConfig holds configuration for webhook delivery.

type DeliveryService

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

DeliveryService handles webhook deliveries.

func NewDeliveryService

func NewDeliveryService(secret string, config DeliveryConfig, logger *slog.Logger) *DeliveryService

NewDeliveryService creates a new webhook delivery service.

func (*DeliveryService) Deliver

func (s *DeliveryService) Deliver(ctx context.Context, eventType string, url string, payload interface{}) (*Delivery, error)

Deliver sends a webhook to the specified URL.

Jump to

Keyboard shortcuts

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