webhook

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: MIT Imports: 16 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 webhook is the shared GitHub-webhook HTTP server every controller embeds: HMAC-SHA256 signature validation on the raw body, immediate 202 acknowledgement into a bounded worker pool, delivery-ID deduplication, and health/readiness endpoints with graceful drain.

Handlers must be idempotent — GitHub redelivers, the dedup window is finite, and every controller pairs the webhook fast path with a reconcile loop that converges missed or dropped deliveries anyway.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// Addr is the listen address, e.g. ":8080".
	Addr string
	// Secret is the shared webhook secret used to validate
	// X-Hub-Signature-256.
	Secret []byte
	// Path is the webhook endpoint path. Default "/webhook".
	Path string
	// Workers is the handler pool size. Default 4.
	Workers int
	// QueueSize bounds the delivery queue; a full queue answers 503 so
	// GitHub redelivers. Default 64.
	QueueSize int
	// Ready optionally gates /readyz; nil means ready once serving.
	Ready func() bool
}

Config configures a Server.

type Event

type Event struct {
	// Type is the X-GitHub-Event header value, e.g. "code_scanning_alert".
	Type string
	// DeliveryID is the X-GitHub-Delivery GUID.
	DeliveryID string
	// Payload is the raw JSON body.
	Payload []byte
}

Event is one validated webhook delivery.

type Handler

type Handler interface {
	Handle(ctx context.Context, e Event) error
}

Handler consumes validated deliveries. Handle runs on a worker goroutine; returning an error records the failure but is not retried here — the reconcile loop is the retry mechanism.

type HandlerFunc

type HandlerFunc func(ctx context.Context, e Event) error

HandlerFunc adapts a function to Handler.

func (HandlerFunc) Handle

func (f HandlerFunc) Handle(ctx context.Context, e Event) error

Handle implements Handler.

type Server

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

Server is the webhook HTTP server.

func NewServer

func NewServer(cfg Config, log *slog.Logger, h Handler) *Server

NewServer builds a Server; defaults are applied here so the zero Config fields need no ceremony at call sites.

func (*Server) Run

func (s *Server) Run(ctx context.Context) error

Run serves until ctx is cancelled, then drains: the listener shuts down gracefully, queued deliveries finish, and the worker pool exits.

Jump to

Keyboard shortcuts

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