Documentation
¶
Overview ¶
Package cloudevent provides types for working with CloudEvents.
Index ¶
Constants ¶
const SpecVersion = "1.0"
SpecVersion is the version of the CloudEvents spec.
Variables ¶
This section is empty.
Functions ¶
func AddNonColumnFieldsToExtras ¶ added in v0.2.0
func AddNonColumnFieldsToExtras(event *CloudEventHeader) map[string]any
AddNonColumnFieldsToExtras adds fields without dedicated columns to Extras. Returns nil when there are no extras and no non-column fields to add.
func BytesForSignature ¶ added in v0.1.6
BytesForSignature returns the bytes that were signed (wire form of data or data_base64) for a RawEvent. Use for signature verification; not the same as Data when the CE used data_base64.
func IsJSONDataContentType ¶ added in v0.1.5
IsJSONDataContentType returns true if the MIME type indicates a JSON payload. Matches "application/json" and any "+json" suffix type (e.g. "application/cloudevents+json").
func RestoreNonColumnFields ¶ added in v0.2.0
func RestoreNonColumnFields(event *CloudEventHeader)
RestoreNonColumnFields restores non-column fields from Extras.
Types ¶
type CloudEvent ¶
type CloudEvent[A any] struct { CloudEventHeader // Data contains domain-specific information about the event. Data A `json:"data"` DataBase64 string `json:"data_base64,omitempty"` }
CloudEvent represents an event according to the CloudEvents spec. To Add extra headers to the CloudEvent, add them to the Extras map. See https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/spec.md
func (CloudEvent[A]) MarshalJSON ¶
func (c CloudEvent[A]) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for CloudEvent[A].
func (*CloudEvent[A]) UnmarshalJSON ¶
func (c *CloudEvent[A]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for CloudEvent. It transparently handles both "data" and "data_base64" wire formats. For RawEvent (CloudEvent[json.RawMessage]), Data is set to the raw payload bytes.
type CloudEventHeader ¶
type CloudEventHeader struct {
// SpecVersion is the version of CloudEvents specification used.
// This is always hardcoded "1.0".
SpecVersion string `json:"specversion"`
// Type describes the type of event. It should generally be a reverse-DNS
// name.
Type string `json:"type"`
// Source is the context in which the event happened. In a distributed system it might consist of multiple Producers.
Source string `json:"source"`
// Subject is an optional field identifying the subject of the event within
// the context of the event producer. In practice, we always set this.
Subject string `json:"subject"`
// ID is an identifier for the event. The combination of ID and Source must
// be unique.
ID string `json:"id"`
// Time is an optional field giving the time at which the event occurred. In
// practice, we always set this.
Time time.Time `json:"time"`
// DataContentType is an optional MIME type for the data field. We almost
// always serialize to JSON and in that case this field is implicitly
// "application/json".
DataContentType string `json:"datacontenttype,omitempty"`
// DataSchema is an optional URI pointing to a schema for the data field.
DataSchema string `json:"dataschema,omitempty"`
// DataVersion is the version of the data type.
DataVersion string `json:"dataversion,omitempty"`
// Producer is a specific instance, process or device that creates the data structure describing the CloudEvent.
Producer string `json:"producer"`
// Signature hold the signature of the a cloudevent's data field.
Signature string `json:"signature,omitempty"`
// Tags are a list of tags that can be used to filter events.
Tags []string `json:"tags,omitempty"`
// Extras contains any additional fields that are not part of the CloudEvent excluding the data field.
Extras map[string]any `json:"-"`
}
CloudEventHeader contains the metadata for any CloudEvent. Field order matches the JSON Event Format: specversion, type, source, subject, id, time, then optional/extension attributes. See https://github.com/cloudevents/spec/blob/main/cloudevents/formats/json-format.md To add extra headers to the CloudEvent, add them to the Extras map.
func DecodeHeader ¶ added in v0.1.6
func DecodeHeader(data []byte) (CloudEventHeader, error)
DecodeHeader parses only the CloudEvent header fields from JSON, skipping the data payload. More efficient than unmarshaling a full event when only metadata is needed (e.g. for scaling).
func (*CloudEventHeader) Equals ¶
func (c *CloudEventHeader) Equals(other CloudEventHeader) bool
Equals returns true if the two CloudEventHeaders share the same IndexKey.
func (CloudEventHeader) Key ¶ added in v0.0.3
func (c CloudEventHeader) Key() string
Key returns the unique identifier for the CloudEvent.
func (CloudEventHeader) MarshalJSON ¶
func (c CloudEventHeader) MarshalJSON() ([]byte, error)
MarshalJSON implements custom JSON marshaling for CloudEventHeader.
func (*CloudEventHeader) UnmarshalJSON ¶
func (c *CloudEventHeader) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling for CloudEventHeader.
type RawEvent ¶
type RawEvent = CloudEvent[json.RawMessage]
RawEvent is a cloudevent with a json.RawMessage data field. It supports both "data" and "data_base64" (CloudEvents JSON spec).
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
migrations
command
|
|
|
Package types provides event type constants for CloudEvents.
|
Package types provides event type constants for CloudEvents. |