Documentation
¶
Overview ¶
Package cloudevents implements the transport-independent CloudEvents 1.0 information model together with explicitly selected event formats, protocol bindings, and extensions.
The package is an interoperability envelope, not an event bus, event store, queue, outbox, workflow engine, schema registry, or canonical domain-event model. Constructors and decoders own retained mutable input. The core does no network I/O, schema resolution, global registration, telemetry, or background work.
Index ¶
- Constants
- Variables
- func EncodeHTTP(events []Event, mode ContentMode) (http.Header, []byte, error)
- func EncodeJSON(event Event) ([]byte, error)
- func EncodeJSONBatch(events []Event) ([]byte, error)
- func EncodeKafkaWithReport(event Event, mode ContentMode, key []byte) (KafkaRecord, ConversionReport, error)
- func KafkaPartitionKey(event Event) ([]byte, bool)
- func ValidateSchema(ctx context.Context, event Event, validator SchemaValidator) error
- type AdapterLoss
- type AdapterReport
- type Attribute
- func NewBinaryAttribute(value []byte) Attribute
- func NewBooleanAttribute(value bool) Attribute
- func NewIntegerAttribute(value int64) (Attribute, error)
- func NewPartitionKeyAttribute(value string) (Attribute, error)
- func NewStringAttribute(value string) (Attribute, error)
- func NewTimestampAttribute(value time.Time) Attribute
- func NewTraceParentAttribute(value string) (Attribute, error)
- func NewTraceStateAttribute(value string) (Attribute, error)
- func NewURIAttribute(value string) (Attribute, error)
- func NewURIReferenceAttribute(value string) (Attribute, error)
- type AttributeKind
- type Attributes
- type ContentMode
- type ConversionLoss
- type ConversionReport
- type Data
- type DataKind
- type Event
- func (e Event) Data() Data
- func (e Event) DataContentType() (string, bool)
- func (e Event) DataSchema() (string, bool)
- func (e Event) Extension(name string) (Attribute, bool)
- func (e Event) Extensions() map[string]Attribute
- func (e Event) ID() string
- func (e Event) Source() string
- func (e Event) SpecVersion() string
- func (e Event) Subject() (string, bool)
- func (e Event) Time() (time.Time, bool)
- func (e Event) Type() string
- func (e Event) Validate() error
- type HTTPMessage
- type Issue
- type IssueCode
- type KafkaHeader
- type KafkaMessage
- type KafkaRecord
- type Limits
- type SchemaValidator
- type ValidationError
Constants ¶
const ( JSONMediaType = "application/cloudevents+json" JSONBatchMediaType = "application/cloudevents-batch+json" )
Variables ¶
var ( // ErrSchemaRequired reports that explicit validation was requested for an // event without a dataschema URI. ErrSchemaRequired = errors.New("cloudevents: schema URI required") // ErrDataRequired reports that explicit validation was requested for an // event without data. ErrDataRequired = errors.New("cloudevents: event data required") // ErrSchemaValidatorRequired reports a nil opt-in validator. ErrSchemaValidatorRequired = errors.New("cloudevents: schema validator required") // ErrContextRequired reports a nil context passed to an explicit operation. ErrContextRequired = errors.New("cloudevents: context required") )
var ErrConversionLoss = errors.New("cloudevents: conversion loss")
ErrConversionLoss identifies an encoding that would change declared event data or metadata without an explicit loss report.
var ErrInvalidAdapterInput = errors.New("cloudevents golib adapter: invalid input")
ErrInvalidAdapterInput classifies an absent or malformed optional adapter input. Target adapters wrap this sentinel while preserving the safe cause.
var ErrInvalidAttribute = errors.New("cloudevents: invalid attribute")
ErrInvalidAttribute identifies a context value outside the CloudEvents type system.
var ErrInvalidData = errors.New("cloudevents: invalid data")
ErrInvalidData identifies event data that cannot be represented by its declared runtime kind.
var ErrInvalidEvent = errors.New("cloudevents: invalid event")
ErrInvalidEvent identifies a CloudEvent that violates the supported specification contract.
var ErrLimitExceeded = errors.New("cloudevents: limit exceeded")
ErrLimitExceeded identifies an input rejected before an unchecked allocation or conversion.
var ErrMetadataCollision = errors.New("cloudevents golib adapter: metadata collision")
ErrMetadataCollision reports canonical metadata that conflicts with an existing CloudEvents value and therefore cannot be overwritten.
var ErrSchemaMapping = errors.New("cloudevents golib adapter: schema mapping")
ErrSchemaMapping reports an absent, conflicting, or unsupported explicit schema selection in an optional adapter.
var ErrSchemaViolation = errors.New("cloudevents golib adapter: schema violation")
ErrSchemaViolation reports a valid event payload that does not satisfy the explicitly selected schema.
var ErrUnsupportedMode = errors.New("cloudevents: unsupported content mode")
ErrUnsupportedMode identifies a content mode or event format this module does not implement.
var ErrUntrustedMetadata = errors.New("cloudevents golib adapter: metadata is untrusted")
ErrUntrustedMetadata reports an attempt to adopt inbound identity metadata without an explicit trust decision.
Functions ¶
func EncodeHTTP ¶
EncodeHTTP maps events without implicit representation loss. Use EncodeHTTPWithReport to accept and inspect target-binding changes.
func EncodeJSON ¶
EncodeJSON serializes event without implicit representation loss. Use EncodeJSONWithReport when the target JSON format cannot retain every declared in-memory distinction.
func EncodeJSONBatch ¶
EncodeJSONBatch serializes events without implicit representation loss.
func EncodeKafkaWithReport ¶
func EncodeKafkaWithReport(event Event, mode ContentMode, key []byte) (KafkaRecord, ConversionReport, error)
EncodeKafkaWithReport maps one Event to the stable Kafka protocol binding while reporting every representation change. Kafka does not define batch mode. The supplied key is copied unchanged.
func KafkaPartitionKey ¶
KafkaPartitionKey implements the official binding's opt-in partitionkey mapper. It does not modify the Event.
func ValidateSchema ¶
func ValidateSchema(ctx context.Context, event Event, validator SchemaValidator) error
ValidateSchema invokes a caller-supplied validator for an event that declares both dataschema and data. The validator receives an owned data copy.
Types ¶
type AdapterLoss ¶ added in v1.1.0
AdapterLoss describes one value that a selected adapter target cannot represent. It contains field names and reasons, never field values.
type AdapterReport ¶ added in v1.1.0
type AdapterReport struct {
Losses []AdapterLoss
}
AdapterReport makes every optional-adapter conversion loss explicit.
type Attribute ¶
type Attribute struct {
// contains filtered or unexported fields
}
Attribute is an immutable CloudEvents context attribute value.
func NewBinaryAttribute ¶
NewBinaryAttribute constructs a Binary context attribute and takes a copy of value.
func NewBooleanAttribute ¶
NewBooleanAttribute constructs a Boolean context attribute.
func NewIntegerAttribute ¶
NewIntegerAttribute constructs a 32-bit Integer context attribute.
func NewPartitionKeyAttribute ¶
NewPartitionKeyAttribute constructs the selected partitioning extension.
func NewStringAttribute ¶
NewStringAttribute constructs a string-valued context attribute.
func NewTimestampAttribute ¶
NewTimestampAttribute constructs an RFC 3339 Timestamp context attribute.
func NewTraceParentAttribute ¶
NewTraceParentAttribute constructs the selected distributed-tracing extension's W3C traceparent value.
func NewTraceStateAttribute ¶
NewTraceStateAttribute constructs the selected distributed-tracing extension's W3C tracestate value.
func NewURIAttribute ¶
NewURIAttribute constructs an absolute URI context attribute.
func NewURIReferenceAttribute ¶
NewURIReferenceAttribute constructs a URI-reference context attribute.
func (Attribute) Bytes ¶
Bytes returns a copy of a Binary attribute. It returns nil for every other attribute type.
func (Attribute) Kind ¶
func (a Attribute) Kind() AttributeKind
Kind returns the CloudEvents abstract attribute type.
type AttributeKind ¶
type AttributeKind uint8
AttributeKind is a CloudEvents abstract context-attribute type.
const ( AttributeString AttributeKind AttributeBoolean AttributeInteger AttributeBinary AttributeURI AttributeURIReference AttributeTimestamp )
type Attributes ¶
type Attributes struct {
ID string
Source string
Type string
DataContentType string
DataSchema string
Subject string
Time *time.Time
Extensions map[string]Attribute
}
Attributes contains the standard and extension context attributes used to construct an Event. NewEvent takes ownership by copying mutable inputs.
type ContentMode ¶
type ContentMode uint8
ContentMode identifies a CloudEvents protocol-binding content mode.
const ( BinaryMode ContentMode StructuredMode BatchMode )
type ConversionLoss ¶
ConversionLoss identifies one declared field whose representation changes in a target event format or protocol binding. It never contains field data.
type ConversionReport ¶
type ConversionReport struct {
Losses []ConversionLoss
}
ConversionReport makes every representation change explicit. Losses are sorted by field and reason so callers can compare and persist reports.
func EncodeHTTPWithReport ¶
func EncodeHTTPWithReport(events []Event, mode ContentMode) (http.Header, []byte, ConversionReport, error)
EncodeHTTPWithReport maps events to HTTP headers and an owned body while reporting every representation change. Binary and structured modes require exactly one event; batch mode accepts zero or more events.
func EncodeJSONBatchWithReport ¶
func EncodeJSONBatchWithReport(events []Event) ([]byte, ConversionReport, error)
EncodeJSONBatchWithReport serializes events using the normative JSON batch format and reports every per-event representation change.
func EncodeJSONWithReport ¶
func EncodeJSONWithReport(event Event) ([]byte, ConversionReport, error)
EncodeJSONWithReport serializes event using the CloudEvents JSON event format and reports every representation change. Member names are sorted lexicographically as a package determinism policy; CloudEvents does not require that ordering.
type Data ¶
type Data struct {
// contains filtered or unexported fields
}
Data is an immutable CloudEvents data value.
func NewBinaryData ¶
NewBinaryData constructs binary event data and takes a copy of value.
func NewJSONData ¶
NewJSONData constructs JSON-valued event data and takes a copy of value.
func NewTextData ¶
NewTextData constructs textual event data.
type DataKind ¶
type DataKind uint8
DataKind distinguishes absent data from JSON, textual, and binary runtime values. The distinction controls normative event-format serialization.
type Event ¶
type Event struct {
// contains filtered or unexported fields
}
Event is an immutable CloudEvent using the stable 1.0 specification.
func DecodeJSON ¶
DecodeJSON parses one CloudEvent in the JSON event format without performing I/O. It takes ownership of all retained input.
func DecodeJSONBatch ¶
DecodeJSONBatch parses the normative JSON batch format. Empty batches are valid. Every returned Event owns its storage.
func NewEvent ¶
func NewEvent(attributes Attributes, data Data) (Event, error)
NewEvent validates and constructs an immutable CloudEvent.
func (Event) DataContentType ¶
DataContentType returns the data media type and whether it is present.
func (Event) DataSchema ¶
DataSchema returns the absolute schema URI and whether it is present.
func (Event) Extensions ¶
Extensions returns an independently owned copy of all extension context attributes, including attributes unknown to this package.
func (Event) SpecVersion ¶
SpecVersion returns the stable CloudEvents specification version.
type HTTPMessage ¶
type HTTPMessage struct {
Mode ContentMode
Events []Event
}
HTTPMessage is a decoded CloudEvents HTTP message. Binary and structured messages contain one Event; batch messages may contain zero or more.
func DecodeHTTP ¶
func DecodeHTTP(ctx context.Context, header http.Header, body io.Reader, limits Limits) (HTTPMessage, error)
DecodeHTTP maps an HTTP header and body to CloudEvents. The caller retains ownership of body; DecodeHTTP never closes it. Cancellation can interrupt cancellation-aware readers and is checked before and after the bounded read.
type IssueCode ¶
type IssueCode string
IssueCode is a stable, value-free validation diagnostic.
const ( IssueRequired IssueCode = "required" IssueInvalidString IssueCode = "invalid_string" IssueInvalidURIReference IssueCode = "invalid_uri_reference" IssueAbsoluteURIRequired IssueCode = "absolute_uri_required" IssueInvalidMediaType IssueCode = "invalid_media_type" IssueInvalidName IssueCode = "invalid_name" IssueReservedName IssueCode = "reserved_name" IssueInvalidAttribute IssueCode = "invalid_attribute" )
type KafkaHeader ¶
KafkaHeader is a Kafka record header. Value is always caller-owned on public input and output boundaries.
type KafkaMessage ¶
type KafkaMessage struct {
Mode ContentMode
Event Event
Key []byte
TransportHeaders []KafkaHeader
}
KafkaMessage is a decoded binding result. Transport headers are headers not owned by the CloudEvents binding and are returned without interpretation.
func DecodeKafka ¶
func DecodeKafka(record KafkaRecord, limits Limits) (KafkaMessage, error)
DecodeKafka decodes the stable Kafka protocol binding without broker I/O.
type KafkaRecord ¶
type KafkaRecord struct {
Key []byte
Value []byte
Headers []KafkaHeader
}
KafkaRecord is the transport-neutral portion of a Kafka record owned by the CloudEvents binding. Topic, partition, offset, timestamp, retries, and broker settlement remain owned by the Kafka caller.
func EncodeKafka ¶
func EncodeKafka(event Event, mode ContentMode, key []byte) (KafkaRecord, error)
EncodeKafka maps one Event without implicit representation loss. Use EncodeKafkaWithReport to accept and inspect target-binding changes.
type Limits ¶
type Limits struct {
MaxEventBytes int64
MaxDataBytes int64
MaxAttributes int
MaxAttributeNameBytes int
MaxAttributeValueBytes int
MaxDepth int
MaxBatchEvents int
MaxKafkaKeyBytes int
MaxKafkaHeaders int
MaxKafkaHeaderNameBytes int
MaxKafkaHeaderValueBytes int
}
Limits bounds untrusted event formats and protocol bindings before semantic parsing. Values are byte counts unless stated otherwise. Kafka-specific limits cover the record metadata copied by DecodeKafka, including metadata not owned by the CloudEvents binding.
func DefaultLimits ¶
func DefaultLimits() Limits
DefaultLimits accepts the CloudEvents interoperability floor while bounding allocations for ordinary library use.
type SchemaValidator ¶
type SchemaValidator interface {
Validate(ctx context.Context, uri string, contentType string, data []byte) error
}
SchemaValidator is implemented by an explicit JSON Schema or schema-registry adapter. The core package never resolves schemas or performs I/O itself.
type ValidationError ¶
type ValidationError struct {
// contains filtered or unexported fields
}
ValidationError contains canonical, field-sorted validation diagnostics.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Error returns a deterministic diagnostic that never contains rejected values.
func (*ValidationError) Issues ¶
func (e *ValidationError) Issues() []Issue
Issues returns an owned copy of the canonical diagnostics.
func (*ValidationError) Unwrap ¶
func (e *ValidationError) Unwrap() error
Unwrap makes every ValidationError match ErrInvalidEvent.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
adapters
|
|
|
audit
module
|
|
|
correlation
module
|
|
|
event-sourcing
module
|
|
|
golib
module
|
|
|
jsonschema
module
|
|
|
kafka
module
|
|
|
outbox
module
|
|
|
queue
module
|
|
|
rabbitstream
module
|
|
|
schema-registry
module
|
|
|
telemetry
module
|
|
|
tenancy
module
|
|
|
workflow
module
|
|
|
internal
|
|
|
adapter
Package adapter contains shared mechanics for independently released CloudEvents target adapters.
|
Package adapter contains shared mechanics for independently released CloudEvents target adapters. |