cloudevents

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2019 License: Apache-2.0 Imports: 17 Imported by: 114

Documentation

Overview

Package cloudevents provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.

Index

Constants

View Source
const (
	TextJSON                        = "text/json"
	ApplicationJSON                 = "application/json"
	ApplicationXML                  = "application/xml"
	ApplicationCloudEventsJSON      = "application/cloudevents+json"
	ApplicationCloudEventsBatchJSON = "application/cloudevents-batch+json"
)
View Source
const (
	// DataContentEncodingKey is the key to DataContentEncoding for versions that do not support data content encoding
	// directly.
	DataContentEncodingKey = "datacontentencoding"

	// EventTypeVersionKey is the key to EventTypeVersion for versions that do not support event type version directly.
	EventTypeVersionKey = "eventTypeVersion"

	// SubjectKey is the key to Subject for versions that do not support subject directly.
	SubjectKey = "subject"
)
View Source
const (
	Base64 = "base64"
)
View Source
const (
	// CloudEventsVersionV01 represents the version 0.1 of the CloudEvents spec.
	CloudEventsVersionV01 = "0.1"
)
View Source
const (
	// CloudEventsVersionV02 represents the version 0.2 of the CloudEvents spec.
	CloudEventsVersionV02 = "0.2"
)
View Source
const (
	// CloudEventsVersionV03 represents the version 0.3 of the CloudEvents spec.
	CloudEventsVersionV03 = "0.3"
)

Variables

View Source
var (
	// EventMarshalLatencyMs measures the latency in milliseconds for the
	// CloudEvents.Event marshal/unmarshalJSON methods.
	EventMarshalLatencyMs = stats.Float64(
		"cloudevents.io/sdk-go/event/json/latency",
		"The latency in milliseconds of (un)marshalJSON methods for CloudEvents.Event.",
		"ms")
)
View Source
var (
	// LatencyView is an OpenCensus view that shows CloudEvents.Event (un)marshalJSON method latency.
	EventMarshalLatencyView = &view.View{
		Name:        "event/json/latency",
		Measure:     EventMarshalLatencyMs,
		Description: "The distribution of latency inside of (un)marshalJSON methods for CloudEvents.Event.",
		Aggregation: view.Distribution(0, .01, .1, 1, 10, 100, 1000, 10000),
		TagKeys:     observability.LatencyTags(),
	}
)

Functions

func JsonEncode

func JsonEncode(e Event) ([]byte, error)

JsonEncode

func StringOfApplicationCloudEventsBatchJSON

func StringOfApplicationCloudEventsBatchJSON() *string

StringOfApplicationCloudEventsBatchJSON returns a string pointer to "application/cloudevents-batch+json"

func StringOfApplicationCloudEventsJSON

func StringOfApplicationCloudEventsJSON() *string

StringOfApplicationCloudEventsJSON returns a string pointer to "application/cloudevents+json"

func StringOfApplicationJSON

func StringOfApplicationJSON() *string

StringOfApplicationJSON returns a string pointer to "application/json"

func StringOfApplicationXML

func StringOfApplicationXML() *string

StringOfApplicationXML returns a string pointer to "application/xml"

func StringOfBase64

func StringOfBase64() *string

StringOfBase64 returns a string pointer to "Base64"

Types

type Event

type Event struct {
	Context     EventContext
	Data        interface{}
	DataEncoded bool
}

Event represents the canonical representation of a CloudEvent.

func New

func New(version ...string) Event

New returns a new Event, an optional version can be passed to change the default spec version from 0.2 to the provided version.

func (Event) DataAs

func (e Event) DataAs(data interface{}) error

DataAs attempts to populate the provided data object with the event payload. data should be a pointer type.

func (*Event) DataBytes

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

func (Event) DataContentEncoding

func (e Event) DataContentEncoding() string

DataContentEncoding implements EventReader.DataContentEncoding

func (Event) DataContentType

func (e Event) DataContentType() string

DataContentType implements EventReader.DataContentType

func (Event) DataMediaType

func (e Event) DataMediaType() string

DataMediaType returns the parsed DataMediaType of the event. If parsing fails, the empty string is returned. To retrieve the parsing error, use `Context.GetDataMediaType` instead.

func (Event) ExtensionAs

func (e Event) ExtensionAs(name string, obj interface{}) error

ExtensionAs returns Context.ExtensionAs(name, obj)

func (Event) Extensions

func (e Event) Extensions() map[string]interface{}

DataContentEncoding implements EventReader.DataContentEncoding

func (Event) ID

func (e Event) ID() string

ID implements EventReader.ID

func (*Event) JsonDecodeV01

func (e *Event) JsonDecodeV01(body []byte, raw map[string]json.RawMessage) error

JsonDecodeV01 takes in the byte representation of a version 0.1 structured json CloudEvent and returns a cloudevent.Event or an error if there are parsing errors.

func (*Event) JsonDecodeV02

func (e *Event) JsonDecodeV02(body []byte, raw map[string]json.RawMessage) error

JsonDecodeV02 takes in the byte representation of a version 0.2 structured json CloudEvent and returns a cloudevent.Event or an error if there are parsing errors.

func (*Event) JsonDecodeV03

func (e *Event) JsonDecodeV03(body []byte, raw map[string]json.RawMessage) error

JsonDecodeV03 takes in the byte representation of a version 0.3 structured json CloudEvent and returns a cloudevent.Event or an error if there are parsing errors.

func (Event) MarshalJSON

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

MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.

func (Event) SchemaURL

func (e Event) SchemaURL() string

SchemaURL implements EventReader.SchemaURL

func (*Event) SetData

func (e *Event) SetData(obj interface{}) error

SetData implements EventWriter.SetData

func (*Event) SetDataContentEncoding

func (e *Event) SetDataContentEncoding(enc string)

SetDataContentEncoding implements EventWriter.SetDataContentEncoding

func (*Event) SetDataContentType

func (e *Event) SetDataContentType(ct string)

SetDataContentType implements EventWriter.SetDataContentType

func (*Event) SetExtension

func (e *Event) SetExtension(name string, obj interface{})

SetDataContentEncoding implements EventWriter.SetDataContentEncoding

func (*Event) SetID

func (e *Event) SetID(id string)

SetID implements EventWriter.SetID

func (*Event) SetSchemaURL

func (e *Event) SetSchemaURL(s string)

SetSchemaURL implements EventWriter.SetSchemaURL

func (*Event) SetSource

func (e *Event) SetSource(s string)

SetSource implements EventWriter.SetSource

func (*Event) SetSpecVersion

func (e *Event) SetSpecVersion(v string)

SetSpecVersion implements EventWriter.SetSpecVersion

func (*Event) SetSubject

func (e *Event) SetSubject(s string)

SetSubject implements EventWriter.SetSubject

func (*Event) SetTime

func (e *Event) SetTime(t time.Time)

SetTime implements EventWriter.SetTime

func (*Event) SetType

func (e *Event) SetType(t string)

SetType implements EventWriter.SetType

func (Event) Source

func (e Event) Source() string

Source implements EventReader.Source

func (Event) SpecVersion

func (e Event) SpecVersion() string

SpecVersion implements EventReader.SpecVersion

func (Event) String

func (e Event) String() string

String returns a pretty-printed representation of the Event.

func (Event) Subject

func (e Event) Subject() string

Subject implements EventReader.Subject

func (Event) Time

func (e Event) Time() time.Time

Time implements EventReader.Time

func (Event) Type

func (e Event) Type() string

Type implements EventReader.Type

func (*Event) UnmarshalJSON

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

UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.

func (Event) Validate

func (e Event) Validate() error

Validate performs a spec based validation on this event. Validation is dependent on the spec version specified in the event context.

type EventContext

type EventContext interface {
	// EventContextConverter allows for conversion between versions.
	EventContextConverter

	// EventContextReader adds methods for reading context.
	EventContextReader

	// EventContextWriter adds methods for writing to context.
	EventContextWriter

	// Validate the event based on the specifics of the CloudEvents spec version
	// represented by this event context.
	Validate() error

	// Clone clones the event context.
	Clone() EventContext

	// String returns a pretty-printed representation of the EventContext.
	String() string
}

EventContext is conical interface for a CloudEvents Context.

type EventContextConverter

type EventContextConverter interface {
	// AsV01 provides a translation from whatever the "native" encoding of the
	// CloudEvent was to the equivalent in v0.1 field names, moving fields to or
	// from extensions as necessary.
	AsV01() *EventContextV01

	// AsV02 provides a translation from whatever the "native" encoding of the
	// CloudEvent was to the equivalent in v0.2 field names, moving fields to or
	// from extensions as necessary.
	AsV02() *EventContextV02

	// AsV03 provides a translation from whatever the "native" encoding of the
	// CloudEvent was to the equivalent in v0.3 field names, moving fields to or
	// from extensions as necessary.
	AsV03() *EventContextV03
}

type EventContextReader

type EventContextReader interface {
	// GetSpecVersion returns the native CloudEvents Spec version of the event
	// context.
	GetSpecVersion() string
	// GetType returns the CloudEvents type from the context.
	GetType() string
	// GetSource returns the CloudEvents source from the context.
	GetSource() string
	// GetSubject returns the CloudEvents subject from the context.
	GetSubject() string
	// GetID returns the CloudEvents ID from the context.
	GetID() string
	// GetTime returns the CloudEvents creation time from the context.
	GetTime() time.Time
	// GetSchemaURL returns the CloudEvents schema URL (if any) from the
	// context.
	GetSchemaURL() string
	// GetDataContentType returns content type on the context.
	GetDataContentType() string
	// GetDataContentEncoding returns content encoding on the context.
	GetDataContentEncoding() string

	// GetDataMediaType returns the MIME media type for encoded data, which is
	// needed by both encoding and decoding. This is a processed form of
	// GetDataContentType and it may return an error.
	GetDataMediaType() (string, error)

	// ExtensionAs populates the given interface with the CloudEvents extension
	// of the given name from the extension attributes. It returns an error if
	// the extension does not exist, the extension's type does not match the
	// provided type, or if the type is not a supported.
	ExtensionAs(string, interface{}) error

	// GetExtensions returns the full extensions map.
	GetExtensions() map[string]interface{}
}

EventContextReader are the methods required to be a reader of context attributes.

type EventContextV01

type EventContextV01 struct {
	// The version of the CloudEvents specification used by the event.
	CloudEventsVersion string `json:"cloudEventsVersion,omitempty"`
	// ID of the event; must be non-empty and unique within the scope of the producer.
	EventID string `json:"eventID"`
	// Timestamp when the event happened.
	EventTime *types.Timestamp `json:"eventTime,omitempty"`
	// Type of occurrence which has happened.
	EventType string `json:"eventType"`
	// The version of the `eventType`; this is producer-specific.
	EventTypeVersion *string `json:"eventTypeVersion,omitempty"`
	// A link to the schema that the `data` attribute adheres to.
	SchemaURL *types.URLRef `json:"schemaURL,omitempty"`
	// A MIME (RFC 2046) string describing the media type of `data`.
	// TODO: Should an empty string assume `application/json`, or auto-detect the content?
	ContentType *string `json:"contentType,omitempty"`
	// A URI describing the event producer.
	Source types.URLRef `json:"source"`
	// Additional metadata without a well-defined structure.
	Extensions map[string]interface{} `json:"extensions,omitempty"`
}

EventContextV01 holds standard metadata about an event. See https://github.com/cloudevents/spec/blob/v0.1/spec.md#context-attributes for details on these fields.

func (EventContextV01) AsV01

func (ec EventContextV01) AsV01() *EventContextV01

AsV01 implements EventContextConverter.AsV01

func (EventContextV01) AsV02

func (ec EventContextV01) AsV02() *EventContextV02

AsV02 implements EventContextConverter.AsV02

func (EventContextV01) AsV03

func (ec EventContextV01) AsV03() *EventContextV03

AsV03 implements EventContextConverter.AsV03

func (EventContextV01) Clone

func (ec EventContextV01) Clone() EventContext

Clone implements EventContextConverter.Clone

func (EventContextV01) ExtensionAs

func (ec EventContextV01) ExtensionAs(name string, obj interface{}) error

ExtensionAs implements EventContextReader.ExtensionAs

func (EventContextV01) GetDataContentEncoding

func (ec EventContextV01) GetDataContentEncoding() string

GetDataContentEncoding implements EventContextReader.GetDataContentEncoding

func (EventContextV01) GetDataContentType

func (ec EventContextV01) GetDataContentType() string

GetDataContentType implements EventContextReader.GetDataContentType

func (EventContextV01) GetDataMediaType

func (ec EventContextV01) GetDataMediaType() (string, error)

GetDataMediaType implements EventContextReader.GetDataMediaType

func (EventContextV01) GetExtensions

func (ec EventContextV01) GetExtensions() map[string]interface{}

func (EventContextV01) GetID

func (ec EventContextV01) GetID() string

GetID implements EventContextReader.GetID

func (EventContextV01) GetSchemaURL

func (ec EventContextV01) GetSchemaURL() string

GetSchemaURL implements EventContextReader.GetSchemaURL

func (EventContextV01) GetSource

func (ec EventContextV01) GetSource() string

GetSource implements EventContextReader.GetSource

func (EventContextV01) GetSpecVersion

func (ec EventContextV01) GetSpecVersion() string

GetSpecVersion implements EventContextReader.GetSpecVersion

func (EventContextV01) GetSubject

func (ec EventContextV01) GetSubject() string

GetSubject implements EventContextReader.GetSubject

func (EventContextV01) GetTime

func (ec EventContextV01) GetTime() time.Time

GetTime implements EventContextReader.GetTime

func (EventContextV01) GetType

func (ec EventContextV01) GetType() string

GetType implements EventContextReader.GetType

func (*EventContextV01) SetDataContentEncoding

func (ec *EventContextV01) SetDataContentEncoding(e string) error

SetDataContentEncoding implements EventContextWriter.SetDataContentEncoding

func (*EventContextV01) SetDataContentType

func (ec *EventContextV01) SetDataContentType(ct string) error

SetDataContentType implements EventContextWriter.SetDataContentType

func (*EventContextV01) SetExtension

func (ec *EventContextV01) SetExtension(name string, value interface{}) error

SetExtension adds the extension 'name' with value 'value' to the CloudEvents context.

func (*EventContextV01) SetID

func (ec *EventContextV01) SetID(id string) error

SetID implements EventContextWriter.SetID

func (*EventContextV01) SetSchemaURL

func (ec *EventContextV01) SetSchemaURL(u string) error

SetSchemaURL implements EventContextWriter.SetSchemaURL

func (*EventContextV01) SetSource

func (ec *EventContextV01) SetSource(u string) error

SetSource implements EventContextWriter.SetSource

func (*EventContextV01) SetSpecVersion

func (ec *EventContextV01) SetSpecVersion(v string) error

SetSpecVersion implements EventContextWriter.SetSpecVersion

func (*EventContextV01) SetSubject

func (ec *EventContextV01) SetSubject(s string) error

SetSubject implements EventContextWriter.SetSubject

func (*EventContextV01) SetTime

func (ec *EventContextV01) SetTime(t time.Time) error

SetTime implements EventContextWriter.SetTime

func (*EventContextV01) SetType

func (ec *EventContextV01) SetType(t string) error

SetType implements EventContextWriter.SetType

func (EventContextV01) String

func (ec EventContextV01) String() string

String returns a pretty-printed representation of the EventContext.

func (EventContextV01) Validate

func (ec EventContextV01) Validate() error

Validate returns errors based on requirements from the CloudEvents spec. For more details, see https://github.com/cloudevents/spec/blob/v0.1/spec.md

type EventContextV02

type EventContextV02 struct {
	// The version of the CloudEvents specification used by the event.
	SpecVersion string `json:"specversion"`
	// The type of the occurrence which has happened.
	Type string `json:"type"`
	// A URI describing the event producer.
	Source types.URLRef `json:"source"`
	// ID of the event; must be non-empty and unique within the scope of the producer.
	ID string `json:"id"`
	// Timestamp when the event happened.
	Time *types.Timestamp `json:"time,omitempty"`
	// A link to the schema that the `data` attribute adheres to.
	SchemaURL *types.URLRef `json:"schemaurl,omitempty"`
	// A MIME (RFC2046) string describing the media type of `data`.
	// TODO: Should an empty string assume `application/json`, `application/octet-stream`, or auto-detect the content?
	ContentType *string `json:"contenttype,omitempty"`
	// Additional extension metadata beyond the base spec.
	Extensions map[string]interface{} `json:"-"`
}

EventContextV02 represents the non-data attributes of a CloudEvents v0.2 event.

func (EventContextV02) AsV01

func (ec EventContextV02) AsV01() *EventContextV01

AsV01 implements EventContextConverter.AsV01

func (EventContextV02) AsV02

func (ec EventContextV02) AsV02() *EventContextV02

AsV02 implements EventContextConverter.AsV02

func (EventContextV02) AsV03

func (ec EventContextV02) AsV03() *EventContextV03

AsV03 implements EventContextConverter.AsV03

func (EventContextV02) Clone

func (ec EventContextV02) Clone() EventContext

Clone implements EventContextConverter.Clone

func (EventContextV02) ExtensionAs

func (ec EventContextV02) ExtensionAs(name string, obj interface{}) error

ExtensionAs implements EventContext.ExtensionAs

func (EventContextV02) GetDataContentEncoding

func (ec EventContextV02) GetDataContentEncoding() string

GetDataContentEncoding implements EventContextReader.GetDataContentEncoding

func (EventContextV02) GetDataContentType

func (ec EventContextV02) GetDataContentType() string

GetDataContentType implements EventContextReader.GetDataContentType

func (EventContextV02) GetDataMediaType

func (ec EventContextV02) GetDataMediaType() (string, error)

GetDataMediaType implements EventContextReader.GetDataMediaType

func (EventContextV02) GetExtensions

func (ec EventContextV02) GetExtensions() map[string]interface{}

func (EventContextV02) GetID

func (ec EventContextV02) GetID() string

GetID implements EventContextReader.GetID

func (EventContextV02) GetSchemaURL

func (ec EventContextV02) GetSchemaURL() string

GetSchemaURL implements EventContextReader.GetSchemaURL

func (EventContextV02) GetSource

func (ec EventContextV02) GetSource() string

GetSource implements EventContextReader.GetSource

func (EventContextV02) GetSpecVersion

func (ec EventContextV02) GetSpecVersion() string

GetSpecVersion implements EventContextReader.GetSpecVersion

func (EventContextV02) GetSubject

func (ec EventContextV02) GetSubject() string

GetSubject implements EventContextReader.GetSubject

func (EventContextV02) GetTime

func (ec EventContextV02) GetTime() time.Time

GetTime implements EventContextReader.GetTime

func (EventContextV02) GetType

func (ec EventContextV02) GetType() string

GetType implements EventContextReader.GetType

func (*EventContextV02) SetDataContentEncoding

func (ec *EventContextV02) SetDataContentEncoding(e string) error

SetDataContentEncoding implements EventContextWriter.SetDataContentEncoding

func (*EventContextV02) SetDataContentType

func (ec *EventContextV02) SetDataContentType(ct string) error

SetDataContentType implements EventContextWriter.SetDataContentType

func (*EventContextV02) SetExtension

func (ec *EventContextV02) SetExtension(name string, value interface{}) error

SetExtension adds the extension 'name' with value 'value' to the CloudEvents context.

func (*EventContextV02) SetID

func (ec *EventContextV02) SetID(id string) error

SetID implements EventContextWriter.SetID

func (*EventContextV02) SetSchemaURL

func (ec *EventContextV02) SetSchemaURL(u string) error

SetSchemaURL implements EventContextWriter.SetSchemaURL

func (*EventContextV02) SetSource

func (ec *EventContextV02) SetSource(u string) error

SetSource implements EventContextWriter.SetSource

func (*EventContextV02) SetSpecVersion

func (ec *EventContextV02) SetSpecVersion(v string) error

SetSpecVersion implements EventContextWriter.SetSpecVersion

func (*EventContextV02) SetSubject

func (ec *EventContextV02) SetSubject(s string) error

SetSubject implements EventContextWriter.SetSubject

func (*EventContextV02) SetTime

func (ec *EventContextV02) SetTime(t time.Time) error

SetTime implements EventContextWriter.SetTime

func (*EventContextV02) SetType

func (ec *EventContextV02) SetType(t string) error

SetType implements EventContextWriter.SetType

func (EventContextV02) String

func (ec EventContextV02) String() string

String returns a pretty-printed representation of the EventContext.

func (EventContextV02) Validate

func (ec EventContextV02) Validate() error

Validate returns errors based on requirements from the CloudEvents spec. For more details, see https://github.com/cloudevents/spec/blob/v0.2/spec.md

type EventContextV03

type EventContextV03 struct {
	// SpecVersion - The version of the CloudEvents specification used by the event.
	SpecVersion string `json:"specversion"`
	// Type - The type of the occurrence which has happened.
	Type string `json:"type"`
	// Source - A URI describing the event producer.
	Source types.URLRef `json:"source"`
	// Subject - The subject of the event in the context of the event producer
	// (identified by `source`).
	Subject *string `json:"subject,omitempty"`
	// ID of the event; must be non-empty and unique within the scope of the producer.
	ID string `json:"id"`
	// Time - A Timestamp when the event happened.
	Time *types.Timestamp `json:"time,omitempty"`
	// SchemaURL - A link to the schema that the `data` attribute adheres to.
	SchemaURL *types.URLRef `json:"schemaurl,omitempty"`
	// GetDataMediaType - A MIME (RFC2046) string describing the media type of `data`.
	// TODO: Should an empty string assume `application/json`, `application/octet-stream`, or auto-detect the content?
	DataContentType *string `json:"datacontenttype,omitempty"`
	// DataContentEncoding describes the content encoding for the `data` attribute. Valid: nil, `Base64`.
	DataContentEncoding *string `json:"datacontentencoding,omitempty"`
	// Extensions - Additional extension metadata beyond the base spec.
	Extensions map[string]interface{} `json:"-"`
}

EventContextV03 represents the non-data attributes of a CloudEvents v0.3 event.

func (EventContextV03) AsV01

func (ec EventContextV03) AsV01() *EventContextV01

AsV01 implements EventContextConverter.AsV01

func (EventContextV03) AsV02

func (ec EventContextV03) AsV02() *EventContextV02

AsV02 implements EventContextConverter.AsV02

func (EventContextV03) AsV03

func (ec EventContextV03) AsV03() *EventContextV03

AsV03 implements EventContextConverter.AsV03

func (EventContextV03) Clone

func (ec EventContextV03) Clone() EventContext

Clone implements EventContextConverter.Clone

func (EventContextV03) ExtensionAs

func (ec EventContextV03) ExtensionAs(name string, obj interface{}) error

ExtensionAs implements EventContext.ExtensionAs

func (EventContextV03) GetDataContentEncoding

func (ec EventContextV03) GetDataContentEncoding() string

GetDataContentEncoding implements EventContextReader.GetDataContentEncoding

func (EventContextV03) GetDataContentType

func (ec EventContextV03) GetDataContentType() string

GetDataContentType implements EventContextReader.GetDataContentType

func (EventContextV03) GetDataMediaType

func (ec EventContextV03) GetDataMediaType() (string, error)

GetDataMediaType implements EventContextReader.GetDataMediaType

func (EventContextV03) GetExtensions

func (ec EventContextV03) GetExtensions() map[string]interface{}

func (EventContextV03) GetID

func (ec EventContextV03) GetID() string

GetID implements EventContextReader.GetID

func (EventContextV03) GetSchemaURL

func (ec EventContextV03) GetSchemaURL() string

GetSchemaURL implements EventContextReader.GetSchemaURL

func (EventContextV03) GetSource

func (ec EventContextV03) GetSource() string

GetSource implements EventContextReader.GetSource

func (EventContextV03) GetSpecVersion

func (ec EventContextV03) GetSpecVersion() string

GetSpecVersion implements EventContextReader.GetSpecVersion

func (EventContextV03) GetSubject

func (ec EventContextV03) GetSubject() string

GetSubject implements EventContextReader.GetSubject

func (EventContextV03) GetTime

func (ec EventContextV03) GetTime() time.Time

GetTime implements EventContextReader.GetTime

func (EventContextV03) GetType

func (ec EventContextV03) GetType() string

GetType implements EventContextReader.GetType

func (*EventContextV03) SetDataContentEncoding

func (ec *EventContextV03) SetDataContentEncoding(e string) error

SetDataContentEncoding implements EventContextWriter.SetDataContentEncoding

func (*EventContextV03) SetDataContentType

func (ec *EventContextV03) SetDataContentType(ct string) error

SetDataContentType implements EventContextWriter.SetDataContentType

func (*EventContextV03) SetExtension

func (ec *EventContextV03) SetExtension(name string, value interface{}) error

SetExtension adds the extension 'name' with value 'value' to the CloudEvents context.

func (*EventContextV03) SetID

func (ec *EventContextV03) SetID(id string) error

SetID implements EventContextWriter.SetID

func (*EventContextV03) SetSchemaURL

func (ec *EventContextV03) SetSchemaURL(u string) error

SetSchemaURL implements EventContextWriter.SetSchemaURL

func (*EventContextV03) SetSource

func (ec *EventContextV03) SetSource(u string) error

SetSource implements EventContextWriter.SetSource

func (*EventContextV03) SetSpecVersion

func (ec *EventContextV03) SetSpecVersion(v string) error

SetSpecVersion implements EventContextWriter.SetSpecVersion

func (*EventContextV03) SetSubject

func (ec *EventContextV03) SetSubject(s string) error

SetSubject implements EventContextWriter.SetSubject

func (*EventContextV03) SetTime

func (ec *EventContextV03) SetTime(t time.Time) error

SetTime implements EventContextWriter.SetTime

func (*EventContextV03) SetType

func (ec *EventContextV03) SetType(t string) error

SetType implements EventContextWriter.SetType

func (EventContextV03) String

func (ec EventContextV03) String() string

String returns a pretty-printed representation of the EventContext.

func (EventContextV03) Validate

func (ec EventContextV03) Validate() error

Validate returns errors based on requirements from the CloudEvents spec. For more details, see https://github.com/cloudevents/spec/blob/master/spec.md As of Feb 26, 2019, commit 17c32ea26baf7714ad027d9917d03d2fff79fc7e + https://github.com/cloudevents/spec/pull/387 -> datacontentencoding + https://github.com/cloudevents/spec/pull/406 -> subject

type EventContextWriter

type EventContextWriter interface {
	// SetSpecVersion sets the spec version of the context.
	SetSpecVersion(string) error
	// SetType sets the type of the context.
	SetType(string) error
	// SetSource sets the source of the context.
	SetSource(string) error
	// SetSubject sets the subject of the context.
	SetSubject(string) error
	// SetID sets the ID of the context.
	SetID(string) error
	// SetTime sets the time of the context.
	SetTime(time time.Time) error
	// SetSchemaURL sets the schema url of the context.
	SetSchemaURL(string) error
	// SetDataContentType sets the data content type of the context.
	SetDataContentType(string) error
	// SetDataContentEncoding sets the data context encoding of the context.
	SetDataContentEncoding(string) error

	// SetExtension sets the given interface onto the extension attributes
	// determined by the provided name.
	SetExtension(string, interface{}) error
}

EventContextWriter are the methods required to be a writer of context attributes.

type EventReader

type EventReader interface {
	// SpecVersion returns event.Context.GetSpecVersion().
	SpecVersion() string
	// Type returns event.Context.GetType().
	Type() string
	// Source returns event.Context.GetSource().
	Source() string
	// Subject returns event.Context.GetSubject().
	Subject() string
	// ID returns event.Context.GetID().
	ID() string
	// Time returns event.Context.GetTime().
	Time() time.Time
	// SchemaURL returns event.Context.GetSchemaURL().
	SchemaURL() string
	// DataContentType returns event.Context.GetDataContentType().
	DataContentType() string
	// DataMediaType returns event.Context.GetDataMediaType().
	DataMediaType() string
	// DataContentEncoding returns event.Context.GetDataContentEncoding().
	DataContentEncoding() string

	// Extensions returns the event.Context.GetExtensions().
	Extensions() map[string]interface{}

	// ExtensionAs returns event.Context.ExtensionAs(name, obj).
	ExtensionAs(string, interface{}) error

	// ExtensionAs returns event.Context.ExtensionAs(name, obj).
	DataAs(interface{}) error
}

EventWriter is the interface for reading through an event from attributes.

type EventResponse

type EventResponse struct {
	Status int
	Event  *Event
	Reason string
	// Context is transport specific struct to allow for controlling transport
	// response details.
	// For example, see http.TransportResponseContext.
	Context interface{}
}

EventResponse represents the canonical representation of a Response to a CloudEvent from a receiver. Response implementation is Transport dependent.

func (*EventResponse) Error

func (e *EventResponse) Error(status int, reason string)

Error sets the instance of EventResponse to be set with an error code and reason string. Response implementation is Transport dependent.

func (*EventResponse) RespondWith

func (e *EventResponse) RespondWith(status int, event *Event)

RespondWith sets up the instance of EventResponse to be set with status and an event. Response implementation is Transport dependent.

type EventWriter

type EventWriter interface {

	// SetSpecVersion performs event.Context.SetSpecVersion.
	SetSpecVersion(string)
	// SetType performs event.Context.SetType.
	SetType(string)
	// SetSource performs event.Context.SetSource.
	SetSource(string)
	// SetSubject( performs event.Context.SetSubject.
	SetSubject(string)
	// SetID performs event.Context.SetID.
	SetID(string)
	// SetTime performs event.Context.SetTime.
	SetTime(time.Time)
	// SetSchemaURL performs event.Context.SetSchemaURL.
	SetSchemaURL(string)
	// SetDataContentType performs event.Context.SetDataContentType.
	SetDataContentType(string)
	// SetDataContentEncoding performs event.Context.SetDataContentEncoding.
	SetDataContentEncoding(string)

	// SetExtension performs event.Context.SetExtension.
	SetExtension(string, interface{})

	// SetData encodes the given payload with the current encoding settings.
	SetData(interface{}) error
}

EventWriter is the interface for writing through an event onto attributes. If an error is thrown by a sub-component, EventWriter panics.

Directories

Path Synopsis
Package client holds the recommended entry points for interacting with the CloudEvents Golang SDK.
Package client holds the recommended entry points for interacting with the CloudEvents Golang SDK.
Package context holds the last resort overrides and fyi objects that can be passed to clients and transports added to context.Context objects.
Package context holds the last resort overrides and fyi objects that can be passed to clients and transports added to context.Context objects.
Package datacodec holds the data codec registry and adds known encoders and decoders supporting media types such as `application/json` and `application/xml`.
Package datacodec holds the data codec registry and adds known encoders and decoders supporting media types such as `application/json` and `application/xml`.
json
Package json holds the encoder/decoder implementation for `application/json`.
Package json holds the encoder/decoder implementation for `application/json`.
xml
Package xml holds the encoder/decoder implementation for `application/xml`.
Package xml holds the encoder/decoder implementation for `application/xml`.
Package observability holds metrics and tracing recording implementations.
Package observability holds metrics and tracing recording implementations.
Package transport defines interfaces to decouple the client package from transport implementations.
Package transport defines interfaces to decouple the client package from transport implementations.
amqp
Package amqp implements the CloudEvent transport implementation using amqp.
Package amqp implements the CloudEvent transport implementation using amqp.
http
Package http implements the CloudEvent transport implementation using HTTP.
Package http implements the CloudEvent transport implementation using HTTP.
nats
Package nats implements the CloudEvent transport implementation using NATS.
Package nats implements the CloudEvent transport implementation using NATS.
pubsub
Package pubsub implements the CloudEvent transport implementation using pubsub.
Package pubsub implements the CloudEvent transport implementation using pubsub.
Package types provides custom types to support CloudEvents.
Package types provides custom types to support CloudEvents.

Jump to

Keyboard shortcuts

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