cloudevents

package
v0.2.5 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package cloudevents provides encoding and decoding helpers for CloudEvents 1.0. It converts events.Event to/from the CloudEvents structured-content-mode JSON envelope and the binary-content-mode HTTP representation.

Pure stdlib — no third-party dependencies.

Index

Constants

View Source
const ContentType = "application/cloudevents+json"

ContentType is the HTTP Content-Type for structured-mode CloudEvents.

Variables

This section is empty.

Functions

func BinaryDecode

func BinaryDecode(h http.Header, body []byte) (events.Event, error)

BinaryDecode reconstructs an Event from CloudEvents 1.0 binary-content-mode HTTP headers and the request body.

func BinaryEncode

func BinaryEncode(h http.Header, e events.Event) []byte

BinaryEncode sets CloudEvents 1.0 binary-content-mode headers on h and returns the data bytes for the request body. Set the Content-Type header separately using e.DataType (usually "application/json").

func Decode

func Decode(body []byte) (events.Event, error)

Decode parses a CloudEvents 1.0 structured-content-mode JSON body. Returns an error when specversion is absent or not "1.0".

func Encode

func Encode(e events.Event) ([]byte, error)

Encode serialises e as a CloudEvents 1.0 structured-content-mode JSON envelope.

Types

type StructuredEnvelope

type StructuredEnvelope struct {
	// CloudEvents 1.0 core attributes
	SpecVersion     string          `json:"specversion"`
	ID              string          `json:"id"`
	Source          string          `json:"source"`
	Type            string          `json:"type"`
	Subject         string          `json:"subject,omitempty"`
	Time            time.Time       `json:"time"`
	DataContentType string          `json:"datacontenttype,omitempty"`
	Data            json.RawMessage `json:"data,omitempty"`

	// maniflex extension attributes (prefixed with "x" per CE spec)
	Xmodel     string `json:"xmodel,omitempty"`
	Xoperation string `json:"xoperation,omitempty"`
	Xrecordid  string `json:"xrecordid,omitempty"`
	Xactorid   string `json:"xactorid,omitempty"`
	Xtenantid  string `json:"xtenantid,omitempty"`
	Xtraceid   string `json:"xtraceid,omitempty"`
	Xschemaver int    `json:"xschemaver,omitempty"`
}

StructuredEnvelope is the CloudEvents 1.0 structured-content-mode JSON body. The Content-Type of the HTTP body must be "application/cloudevents+json".

Jump to

Keyboard shortcuts

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