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 ¶
const SpecVersion = "1.0"
CloudEvents specification version.
Variables ¶
This section is empty.
Functions ¶
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 ¶
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 ¶
MarshalJSON implements custom JSON marshaling to include extensions at top level.
func (*Event) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling to extract extensions.