cloudevents

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cloudevents provides CloudEvents v1.0.2 serialization and deserialization for gopipe messages. It supports both HTTP protocol binding and JSON format.

Index

Constants

View Source
const SpecVersion = "1.0"

CloudEvents specification version.

Variables

This section is empty.

Functions

func ToMessage

func ToMessage(e *Event) (*message.Message, string, error)

ToMessage converts a CloudEvent to a gopipe message. Returns the message and the topic (from extension attribute).

Types

type Event

type Event struct {
	// Required attributes
	ID          string `json:"id"`
	Source      string `json:"source"`
	SpecVersion string `json:"specversion"`
	Type        string `json:"type"`

	// Optional standard attributes
	Subject         string `json:"subject,omitempty"`
	Time            string `json:"time,omitempty"`
	DataContentType string `json:"datacontenttype,omitempty"`

	// Data payload - one of Data or DataBase64 should be set
	Data       any    `json:"data,omitempty"`
	DataBase64 string `json:"data_base64,omitempty"`

	// Extension attributes (marshaled at top level)
	Extensions map[string]any `json:"-"`
}

Event represents a CloudEvent structure per CloudEvents v1.0.2 spec. It includes required context attributes (id, source, specversion, type), optional attributes (subject, time, datacontenttype), and extension attributes.

Per the JSON format spec, data and data_base64 are mutually exclusive: - data: for JSON-formatted content or string-encoded content - data_base64: for Base64-encoded binary content

func FromMessage

func FromMessage(msg *message.Message, topic string, defaultSource string) *Event

FromMessage converts a gopipe message to a CloudEvent. The topic is stored as an extension attribute. If source is not provided in attributes, defaultSource is used.

func (*Event) MarshalJSON

func (e *Event) MarshalJSON() ([]byte, error)

MarshalJSON implements custom JSON marshaling to include extensions at top level.

func (*Event) UnmarshalJSON

func (e *Event) UnmarshalJSON(data []byte) error

UnmarshalJSON implements custom JSON unmarshaling to extract extensions.

Jump to

Keyboard shortcuts

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