webhook

package
v1.0.0-beta.2 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: GPL-3.0 Imports: 7 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 provides a process-wide hub that routes incoming HTTP webhook requests to registered handlers. Webhook trigger nodes register a path on the hub when they start; the HTTP server forwards matching requests to them. This is the bridge that lets trigger nodes (which only receive a Start(ctx, out) call) react to external HTTP requests without owning a listener themselves.

Index

Constants

View Source
const (
	// PathPrefix is where webhook endpoints are mounted on the HTTP server.
	PathPrefix = "/webhooks/"
)

Variables

View Source
var DefaultHub = NewHub()

DefaultHub is the process-wide hub shared by webhook trigger nodes and the HTTP server.

Functions

This section is empty.

Types

type Handler

type Handler func(Request) Result

Handler processes a delivered webhook request.

type Hub

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

Hub routes incoming webhook requests to handlers keyed by path.

func NewHub

func NewHub() *Hub

NewHub creates an empty Hub.

func (*Hub) Dispatch

func (h *Hub) Dispatch(path string, req Request) (result Result, ok bool)

Dispatch delivers a request to the handler registered for its path and returns its result; ok is false if no handler is registered.

func (*Hub) HandlerFunc

func (h *Hub) HandlerFunc() http.HandlerFunc

HandlerFunc returns an http.HandlerFunc that parses the request and dispatches it to the hub based on the path following PathPrefix. The response status reflects the outcome: 404 unknown path, 400 unreadable body, 413 body over 1 MiB, then the handler's Result (200/401/405/503).

func (*Hub) Has

func (h *Hub) Has(path string) bool

Has reports whether a path is registered.

func (*Hub) Register

func (h *Hub) Register(path string, handler Handler) error

Register binds a handler to a path. It errors if the path is already taken, so two flows can't silently fight over the same webhook URL.

func (*Hub) Unregister

func (h *Hub) Unregister(path string)

Unregister removes the handler for a path.

type Request

type Request struct {
	Method     string
	Path       string
	Query      map[string][]string
	Headers    map[string]string
	Body       interface{}
	RemoteAddr string
	Token      string
}

Request is the normalized representation of an incoming webhook HTTP request delivered to a registered handler.

Credentials are kept out of Headers and Query, which end up in flow payloads (and from there in logs, files, notifications): Cookie, Authorization, X-Webhook-Token and X-PiWorker-* headers and the "token" query parameter are removed. The webhook token, if any, is passed in Token instead (X-Webhook-Token header first, then ?token=).

type Result

type Result int

Result is a handler's verdict on a request; the hub maps it to the HTTP status the caller sees.

const (
	// Accepted: the request was queued into the flow (200).
	Accepted Result = iota
	// Unauthorized: missing or wrong token (401).
	Unauthorized
	// MethodNotAllowed: the node filters on another method (405).
	MethodNotAllowed
	// Dropped: the flow is stopping or its queue is full (503), so the
	// sender knows to retry instead of assuming delivery.
	Dropped
)

Jump to

Keyboard shortcuts

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