envelope

package
v0.19.1237 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package envelope normalizes inbound trigger event payloads. A Decoder understands one wire format (raw JSON, CloudEvents, Pub/Sub push, SNS, Azure Event Grid, Slack Events API) and produces a provider-agnostic Event.

Index

Constants

View Source
const AzureEventGridValidationEventType = "Microsoft.EventGrid.SubscriptionValidationEvent"

AzureEventGridValidationEventType identifies the Event Grid subscription validation handshake event.

View Source
const SlackURLVerificationType = "url_verification"

SlackEventType for URL verification handshake requests.

Variables

This section is empty.

Functions

func ApplySelectors

func ApplySelectors(event *Event, headers http.Header, typeFrom, idFrom FieldSelector) error

ApplySelectors overrides the event ID and type from the configured selectors. Header selectors only apply when the header is present; payload selectors must match exactly one nonempty string.

func AzureEventGridValidationCode

func AzureEventGridValidationCode(event *Event) (string, error)

AzureEventGridValidationCode extracts the subscription validation code from a validation handshake event. It returns "" for regular events.

func DecodeJSON

func DecodeJSON(body []byte) (any, error)

DecodeJSON decodes a JSON document preserving number precision.

func SlackChallenge

func SlackChallenge(event *Event) (string, error)

SlackChallenge extracts the url_verification challenge from a decoded Slack event. It returns "" for regular event callbacks.

func ValidateSelector

func ValidateSelector(selector FieldSelector) error

ValidateSelector rejects selectors that set both sources or use an invalid payload path.

Types

type AzureEventGrid

type AzureEventGrid struct{}

AzureEventGrid decodes an Azure Event Grid delivery containing exactly one event.

func (AzureEventGrid) Decode

func (AzureEventGrid) Decode(_ http.Header, body []byte) (*Event, error)

type CloudEvents

type CloudEvents struct{}

CloudEvents decodes a structured-mode CloudEvents 1.0 envelope. The envelope's own ID becomes the dedupe ID even when selectors override the event ID.

func (CloudEvents) Decode

func (CloudEvents) Decode(_ http.Header, body []byte) (*Event, error)

type Decoder

type Decoder interface {
	Decode(headers http.Header, body []byte) (*Event, error)
}

Decoder decodes one wire format into a normalized Event. A nil Event with a nil error means the request was valid but carries no event to persist (for example an SNS subscription confirmation).

type Event

type Event struct {
	ID          string
	DedupeID    string
	Source      string
	Type        string
	OccurredAt  *time.Time
	Payload     json.RawMessage
	ContentType string
}

Event is a normalized inbound event, independent of the wire format it arrived in.

type FieldSelector

type FieldSelector struct {
	Header  string `json:"header,omitempty"`
	Payload string `json:"payload,omitempty"`
}

FieldSelector extracts an event field from a request header or a JSONPath expression evaluated against the event payload.

type PubSubPush

type PubSubPush struct{}

PubSubPush decodes a Google Pub/Sub push delivery envelope.

func (PubSubPush) Decode

func (PubSubPush) Decode(_ http.Header, body []byte) (*Event, error)

type Raw

type Raw struct{}

Raw decodes an unwrapped JSON event. The event ID defaults to the body digest so retried deliveries dedupe; selectors may override it.

func (Raw) Decode

func (Raw) Decode(headers http.Header, body []byte) (*Event, error)

type SlackEvents

type SlackEvents struct{}

SlackEvents decodes a Slack Events API envelope: either a url_verification handshake or an event_callback wrapping the inner event.

func (SlackEvents) Decode

func (SlackEvents) Decode(_ http.Header, body []byte) (*Event, error)

Jump to

Keyboard shortcuts

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