protocol

package
v1.7.5 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: ? 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 protocol is how services call webhooks: the Protocol interface, and the factory of the protocols, each of which is a package of its own, in this folder, such as github. A new protocol is a package, which is added to protocols.

Index

Constants

View Source
const Default = generic.Name

Default is the protocol of a webhook which has no type

Variables

This section is empty.

Functions

func KeptHeaders

func KeptHeaders(p Protocol, header http.Header) map[string]string

KeptHeaders returns the headers of the call which the protocol keeps, by their canonical names, with their first values, or nil, when there are none

func Names

func Names() []string

Names returns the names of the protocols, in order

Types

type Protocol

type Protocol interface {
	// Name returns the protocol's name, which is a webhook's type, such as
	// github
	Name() string

	// Headers returns the canonical names of the headers which are kept,
	// besides Content-Type, and User-Agent, such as the event's, and the
	// signature's
	Headers() []string

	// Handshake returns the response to a request which checks the webhook,
	// such as a GET, which echoes a challenge, as it's registered, with the
	// secret, and true, or false, when it isn't one, which is a call
	Handshake(r *http.Request, secret string) ([]byte, bool)

	// Check returns nil when a call, of the method, and with the headers, is
	// one which the service makes, such as a POST, with its event, and
	// ErrBadParameter otherwise. It's whether a call looks like the service's,
	// which anyone can make one look like, rather than whether it's verified.
	Check(method string, header http.Header) error

	// Decode returns the body, with its headers, as JSON values, or nil,
	// when it has none, or isn't text
	Decode(header http.Header, body []byte) (json.RawMessage, error)

	// Verify returns nil when the body was signed with the secret, which
	// isn't empty, and ErrForbidden otherwise
	Verify(header http.Header, body []byte, secret string) error

	// Sample returns the headers, and the body, of a call which the service
	// could make, with the identifier of its delivery, such as for a test. It
	// isn't signed.
	Sample(delivery string) (http.Header, []byte)

	// Sign signs the body with the secret, as the service does, in the
	// headers, so it's verified with it
	Sign(header http.Header, body []byte, secret string)

	// Identify returns what happened, such as issues.opened, and the
	// identifier of the delivery, which a delivery which is sent again has
	// too, or empty, when they aren't known
	Identify(header http.Header, values json.RawMessage) (event, delivery string)
}

Protocol is how a service calls its webhooks: which of a call's headers say what it is, how its body is JSON values, how it's verified, with the webhook's secret, and what it says happened, such as GitHub's, whose calls are signed with X-Hub-Signature-256, and say their event, and delivery, in X-GitHub-Event, and X-GitHub-Delivery

func New

func New(name string) (Protocol, error)

New returns the protocol with the name, a webhook's type, which is the default, generic, when it's empty, or ErrBadParameter, when there's none

Directories

Path Synopsis
Package aftership is AfterShip Tracking's webhook protocol: its calls are signed, with the account's webhook secret, in aftership-hmac-sha256, and say what happened, and their delivery, in the body's event, and event_id
Package aftership is AfterShip Tracking's webhook protocol: its calls are signed, with the account's webhook secret, in aftership-hmac-sha256, and say what happened, and their delivery, in the body's event, and event_id
Package common has what the webhook protocols share: their bodies as JSON values, signatures compared in constant time, and a JSON object's fields
Package common has what the webhook protocols share: their bodies as JSON values, signatures compared in constant time, and a JSON object's fields
Package generic is the webhook protocol of a service which has none of its own: its calls are verified by the secret, as a bearer token, when the service can send one, and say nothing of what happened
Package generic is the webhook protocol of a service which has none of its own: its calls are verified by the secret, as a bearer token, when the service can send one, and say nothing of what happened
Package github is GitHub's webhook protocol: its calls are signed, with the secret, in X-Hub-Signature-256, say what happened in X-GitHub-Event, and the body's action, and their delivery in X-GitHub-Delivery.
Package github is GitHub's webhook protocol: its calls are signed, with the secret, in X-Hub-Signature-256, say what happened in X-GitHub-Event, and the body's action, and their delivery in X-GitHub-Delivery.
Package pidgeon is Pidgeon's webhook protocol: its calls are signed, with the endpoint's whsec_ secret, in Pidgeon-Signature, as t=<seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>">, which is too old after five minutes, say what happened in Pidgeon-Event, and the body's type, and their delivery in the body's id
Package pidgeon is Pidgeon's webhook protocol: its calls are signed, with the endpoint's whsec_ secret, in Pidgeon-Signature, as t=<seconds>,v1=<hex HMAC-SHA256 of "<t>.<body>">, which is too old after five minutes, say what happened in Pidgeon-Event, and the body's type, and their delivery in the body's id

Jump to

Keyboard shortcuts

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