Documentation ¶
Overview ¶
Package cloudevents provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
Index ¶
- Constants
- Variables
- func JsonEncode(e Event) ([]byte, error)
- func JsonEncodeLegacy(e Event) ([]byte, error)
- func StringOfApplicationCloudEventsBatchJSON() *string
- func StringOfApplicationCloudEventsJSON() *string
- func StringOfApplicationJSON() *string
- func StringOfApplicationXML() *string
- func StringOfBase64() *string
- func StringOfTextPlain() *string
- type Event
- func (e Event) Clone() Event
- func (e Event) Data() []byte
- func (e Event) DataAs(obj interface{}) error
- func (e Event) DataContentType() string
- func (e Event) DataMediaType() string
- func (e Event) DataSchema() string
- func (e Event) DeprecatedDataContentEncoding() string
- func (e Event) ExtensionAs(name string, obj interface{}) error
- func (e Event) Extensions() map[string]interface{}
- func (e Event) ID() string
- func (e *Event) JsonDecodeV03(body []byte, raw map[string]json.RawMessage) error
- func (e *Event) JsonDecodeV1(body []byte, raw map[string]json.RawMessage) error
- func (e Event) MarshalJSON() ([]byte, error)
- func (e *Event) SetData(contentType string, obj interface{}) error
- func (e *Event) SetDataContentEncoding(enc string)
- func (e *Event) SetDataContentType(ct string)
- func (e *Event) SetDataSchema(s string)
- func (e *Event) SetExtension(name string, obj interface{})
- func (e *Event) SetID(id string)
- func (e *Event) SetSource(s string)
- func (e *Event) SetSpecVersion(v string)
- func (e *Event) SetSubject(s string)
- func (e *Event) SetTime(t time.Time)
- func (e *Event) SetType(t string)
- func (e Event) Source() string
- func (e Event) SpecVersion() string
- func (e Event) String() string
- func (e Event) Subject() string
- func (e Event) Time() time.Time
- func (e Event) Type() string
- func (e *Event) UnmarshalJSON(b []byte) error
- func (e Event) Validate() error
- type EventContext
- type EventContextConverter
- type EventContextReader
- type EventContextV03
- func (ec EventContextV03) AsV03() *EventContextV03
- func (ec EventContextV03) AsV1() *EventContextV1
- func (ec EventContextV03) Clone() EventContext
- func (ec EventContextV03) DeprecatedGetDataContentEncoding() string
- func (ec *EventContextV03) DeprecatedSetDataContentEncoding(e string) error
- func (ec EventContextV03) ExtensionAs(name string, obj interface{}) error
- func (ec EventContextV03) GetDataContentType() string
- func (ec EventContextV03) GetDataMediaType() (string, error)
- func (ec EventContextV03) GetDataSchema() string
- func (ec EventContextV03) GetExtension(key string) (interface{}, error)
- func (ec EventContextV03) GetExtensions() map[string]interface{}
- func (ec EventContextV03) GetID() string
- func (ec EventContextV03) GetSource() string
- func (ec EventContextV03) GetSpecVersion() string
- func (ec EventContextV03) GetSubject() string
- func (ec EventContextV03) GetTime() time.Time
- func (ec EventContextV03) GetType() string
- func (ec *EventContextV03) SetDataContentType(ct string) error
- func (ec *EventContextV03) SetDataSchema(u string) error
- func (ec *EventContextV03) SetExtension(name string, value interface{}) error
- func (ec *EventContextV03) SetID(id string) error
- func (ec *EventContextV03) SetSource(u string) error
- func (ec *EventContextV03) SetSpecVersion(v string) error
- func (ec *EventContextV03) SetSubject(s string) error
- func (ec *EventContextV03) SetTime(t time.Time) error
- func (ec *EventContextV03) SetType(t string) error
- func (ec EventContextV03) String() string
- func (ec EventContextV03) Validate() error
- type EventContextV1
- func (ec EventContextV1) AsV03() *EventContextV03
- func (ec EventContextV1) AsV1() *EventContextV1
- func (ec EventContextV1) Clone() EventContext
- func (ec EventContextV1) DeprecatedGetDataContentEncoding() string
- func (ec *EventContextV1) DeprecatedSetDataContentEncoding(e string) error
- func (ec EventContextV1) ExtensionAs(name string, obj interface{}) error
- func (ec EventContextV1) GetDataContentType() string
- func (ec EventContextV1) GetDataMediaType() (string, error)
- func (ec EventContextV1) GetDataSchema() string
- func (ec EventContextV1) GetExtension(key string) (interface{}, error)
- func (ec EventContextV1) GetExtensions() map[string]interface{}
- func (ec EventContextV1) GetID() string
- func (ec EventContextV1) GetSource() string
- func (ec EventContextV1) GetSpecVersion() string
- func (ec EventContextV1) GetSubject() string
- func (ec EventContextV1) GetTime() time.Time
- func (ec EventContextV1) GetType() string
- func (ec *EventContextV1) SetDataContentType(ct string) error
- func (ec *EventContextV1) SetDataSchema(u string) error
- func (ec *EventContextV1) SetExtension(name string, value interface{}) error
- func (ec *EventContextV1) SetID(id string) error
- func (ec *EventContextV1) SetSource(u string) error
- func (ec *EventContextV1) SetSpecVersion(v string) error
- func (ec *EventContextV1) SetSubject(s string) error
- func (ec *EventContextV1) SetTime(t time.Time) error
- func (ec *EventContextV1) SetType(t string) error
- func (ec EventContextV1) String() string
- func (ec EventContextV1) Validate() error
- type EventContextWriter
- type EventReader
- type EventWriter
Constants ¶
const ( TextPlain = "text/plain" TextJSON = "text/json" ApplicationJSON = "application/json" ApplicationXML = "application/xml" ApplicationCloudEventsJSON = "application/cloudevents+json" ApplicationCloudEventsBatchJSON = "application/cloudevents-batch+json" )
const ( // DataContentEncodingKey is the key to DeprecatedDataContentEncoding 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" )
const (
Base64 = "base64"
)
const (
// CloudEventsVersionV03 represents the version 0.3 of the CloudEvents spec.
CloudEventsVersionV03 = "0.3"
)
const (
// CloudEventsVersionV1 represents the version 1.0 of the CloudEvents spec.
CloudEventsVersionV1 = "1.0"
)
Variables ¶
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") )
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(), } )
var IsAlphaNumeric = regexp.MustCompile(`^[a-zA-Z0-9]+$`).MatchString
Functions ¶
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"
func StringOfTextPlain ¶
func StringOfTextPlain() *string
StringOfTextPlain returns a string pointer to "text/plain"
Types ¶
type Event ¶
type Event struct { Context EventContext DataEncoded []byte DataBinary bool FieldErrors map[string]error }
Event represents the canonical representation of a CloudEvent.
func New ¶
New returns a new Event, an optional version can be passed to change the default spec version from 1.0 to the provided version.
func (Event) DataAs ¶
DataAs attempts to populate the provided data object with the event payload. data should be a pointer type.
func (Event) DataContentType ¶
DataContentType implements EventReader.DataContentType
func (Event) DataMediaType ¶
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) DataSchema ¶
DataSchema implements EventReader.DataSchema
func (Event) DeprecatedDataContentEncoding ¶
DeprecatedDataContentEncoding implements EventReader.DeprecatedDataContentEncoding
func (Event) ExtensionAs ¶
DEPRECATED: Access extensions directly via the e.Extensions() map. Use functions in the types package to convert extension values. For example replace this:
var i int err := e.ExtensionAs("foo", &i)
With this:
i, err := types.ToInteger(e.Extensions["foo"])
func (Event) Extensions ¶
Extensions implements EventReader.Extensions
func (*Event) JsonDecodeV03 ¶
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) JsonDecodeV1 ¶
JsonDecodeV1 takes in the byte representation of a version 1.0 structured json CloudEvent and returns a cloudevent.Event or an error if there are parsing errors.
func (Event) MarshalJSON ¶
MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.
func (*Event) SetDataContentEncoding ¶
DeprecatedSetDataContentEncoding implements EventWriter.DeprecatedSetDataContentEncoding
func (*Event) SetDataContentType ¶
SetDataContentType implements EventWriter.SetDataContentType
func (*Event) SetDataSchema ¶
SetDataSchema implements EventWriter.SetDataSchema
func (*Event) SetExtension ¶
SetExtension implements EventWriter.SetExtension
func (*Event) SetSpecVersion ¶
SetSpecVersion implements EventWriter.SetSpecVersion
func (*Event) SetSubject ¶
SetSubject implements EventWriter.SetSubject
func (Event) SpecVersion ¶
SpecVersion implements EventReader.SpecVersion
func (*Event) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.
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 { // 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 // AsV1 provides a translation from whatever the "native" encoding of the // CloudEvent was to the equivalent in v1.0 field names, moving fields to or // from extensions as necessary. AsV1() *EventContextV1 }
EventContextConverter are the methods that allow for event version conversion.
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 // GetDataSchema returns the CloudEvents schema URL (if any) from the // context. GetDataSchema() string // GetDataContentType returns content type on the context. GetDataContentType() string // DeprecatedGetDataContentEncoding returns content encoding on the context. DeprecatedGetDataContentEncoding() 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) // DEPRECATED: Access extensions directly via the GetExtensions() // For example replace this: // // var i int // err := ec.ExtensionAs("foo", &i) // // With this: // // i, err := types.ToInteger(ec.GetExtensions["foo"]) // ExtensionAs(string, interface{}) error // GetExtensions returns the full extensions map. // // Extensions use the CloudEvents type system, details in package cloudevents/types. GetExtensions() map[string]interface{} // GetExtension returns the extension associated with with the given key. // The given key is case insensitive. If the extension can not be found, // an error will be returned. GetExtension(string) (interface{}, error) }
EventContextReader are the methods required to be a reader of context attributes.
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.URIRef `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"` // DataSchema - A link to the schema that the `data` attribute adheres to. SchemaURL *types.URIRef `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"` // DeprecatedDataContentEncoding 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) AsV03 ¶
func (ec EventContextV03) AsV03() *EventContextV03
AsV03 implements EventContextConverter.AsV03
func (EventContextV03) AsV1 ¶
func (ec EventContextV03) AsV1() *EventContextV1
AsV04 implements EventContextConverter.AsV04
func (EventContextV03) Clone ¶
func (ec EventContextV03) Clone() EventContext
Clone implements EventContextConverter.Clone
func (EventContextV03) DeprecatedGetDataContentEncoding ¶
func (ec EventContextV03) DeprecatedGetDataContentEncoding() string
DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding
func (*EventContextV03) DeprecatedSetDataContentEncoding ¶
func (ec *EventContextV03) DeprecatedSetDataContentEncoding(e string) error
DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding
func (EventContextV03) ExtensionAs ¶
func (ec EventContextV03) ExtensionAs(name string, obj interface{}) error
ExtensionAs implements EventContext.ExtensionAs
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) GetDataSchema ¶
func (ec EventContextV03) GetDataSchema() string
GetDataSchema implements EventContextReader.GetDataSchema
func (EventContextV03) GetExtension ¶
func (ec EventContextV03) GetExtension(key string) (interface{}, error)
GetExtension implements EventContextReader.GetExtension
func (EventContextV03) GetExtensions ¶
func (ec EventContextV03) GetExtensions() map[string]interface{}
GetExtensions implements EventContextReader.GetExtensions
func (EventContextV03) GetID ¶
func (ec EventContextV03) GetID() string
GetID implements EventContextReader.GetID
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) SetDataContentType ¶
func (ec *EventContextV03) SetDataContentType(ct string) error
SetDataContentType implements EventContextWriter.SetDataContentType
func (*EventContextV03) SetDataSchema ¶
func (ec *EventContextV03) SetDataSchema(u string) error
SetDataSchema implements EventContextWriter.SetDataSchema
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) 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 EventContextV1 ¶
type EventContextV1 struct { // ID of the event; must be non-empty and unique within the scope of the producer. // +required ID string `json:"id"` // Source - A URI describing the event producer. // +required Source types.URIRef `json:"source"` // SpecVersion - The version of the CloudEvents specification used by the event. // +required SpecVersion string `json:"specversion"` // Type - The type of the occurrence which has happened. // +required Type string `json:"type"` // DataContentType - A MIME (RFC2046) string describing the media type of `data`. // +optional DataContentType *string `json:"datacontenttype,omitempty"` // Subject - The subject of the event in the context of the event producer // (identified by `source`). // +optional Subject *string `json:"subject,omitempty"` // Time - A Timestamp when the event happened. // +optional Time *types.Timestamp `json:"time,omitempty"` // DataSchema - A link to the schema that the `data` attribute adheres to. // +optional DataSchema *types.URI `json:"dataschema,omitempty"` // Extensions - Additional extension metadata beyond the base spec. // +optional Extensions map[string]interface{} `json:"-"` }
EventContextV1 represents the non-data attributes of a CloudEvents v1.0 event.
func (EventContextV1) AsV03 ¶
func (ec EventContextV1) AsV03() *EventContextV03
AsV03 implements EventContextConverter.AsV03
func (EventContextV1) AsV1 ¶
func (ec EventContextV1) AsV1() *EventContextV1
AsV04 implements EventContextConverter.AsV04
func (EventContextV1) Clone ¶
func (ec EventContextV1) Clone() EventContext
Clone implements EventContextConverter.Clone
func (EventContextV1) DeprecatedGetDataContentEncoding ¶
func (ec EventContextV1) DeprecatedGetDataContentEncoding() string
DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding
func (*EventContextV1) DeprecatedSetDataContentEncoding ¶
func (ec *EventContextV1) DeprecatedSetDataContentEncoding(e string) error
DeprecatedSetDataContentEncoding implements EventContextWriter.DeprecatedSetDataContentEncoding
func (EventContextV1) ExtensionAs ¶
func (ec EventContextV1) ExtensionAs(name string, obj interface{}) error
ExtensionAs implements EventContext.ExtensionAs
func (EventContextV1) GetDataContentType ¶
func (ec EventContextV1) GetDataContentType() string
GetDataContentType implements EventContextReader.GetDataContentType
func (EventContextV1) GetDataMediaType ¶
func (ec EventContextV1) GetDataMediaType() (string, error)
GetDataMediaType implements EventContextReader.GetDataMediaType
func (EventContextV1) GetDataSchema ¶
func (ec EventContextV1) GetDataSchema() string
GetDataSchema implements EventContextReader.GetDataSchema
func (EventContextV1) GetExtension ¶
func (ec EventContextV1) GetExtension(key string) (interface{}, error)
GetExtension implements EventContextReader.GetExtension
func (EventContextV1) GetExtensions ¶
func (ec EventContextV1) GetExtensions() map[string]interface{}
GetExtensions implements EventContextReader.GetExtensions
func (EventContextV1) GetID ¶
func (ec EventContextV1) GetID() string
GetID implements EventContextReader.GetID
func (EventContextV1) GetSource ¶
func (ec EventContextV1) GetSource() string
GetSource implements EventContextReader.GetSource
func (EventContextV1) GetSpecVersion ¶
func (ec EventContextV1) GetSpecVersion() string
GetSpecVersion implements EventContextReader.GetSpecVersion
func (EventContextV1) GetSubject ¶
func (ec EventContextV1) GetSubject() string
GetSubject implements EventContextReader.GetSubject
func (EventContextV1) GetTime ¶
func (ec EventContextV1) GetTime() time.Time
GetTime implements EventContextReader.GetTime
func (EventContextV1) GetType ¶
func (ec EventContextV1) GetType() string
GetType implements EventContextReader.GetType
func (*EventContextV1) SetDataContentType ¶
func (ec *EventContextV1) SetDataContentType(ct string) error
SetDataContentType implements EventContextWriter.SetDataContentType
func (*EventContextV1) SetDataSchema ¶
func (ec *EventContextV1) SetDataSchema(u string) error
SetDataSchema implements EventContextWriter.SetDataSchema
func (*EventContextV1) SetExtension ¶
func (ec *EventContextV1) SetExtension(name string, value interface{}) error
SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. This function fails if the name doesn't respect the regex ^[a-zA-Z0-9]+$
func (*EventContextV1) SetID ¶
func (ec *EventContextV1) SetID(id string) error
SetID implements EventContextWriter.SetID
func (*EventContextV1) SetSource ¶
func (ec *EventContextV1) SetSource(u string) error
SetSource implements EventContextWriter.SetSource
func (*EventContextV1) SetSpecVersion ¶
func (ec *EventContextV1) SetSpecVersion(v string) error
SetSpecVersion implements EventContextWriter.SetSpecVersion
func (*EventContextV1) SetSubject ¶
func (ec *EventContextV1) SetSubject(s string) error
SetSubject implements EventContextWriter.SetSubject
func (*EventContextV1) SetTime ¶
func (ec *EventContextV1) SetTime(t time.Time) error
SetTime implements EventContextWriter.SetTime
func (*EventContextV1) SetType ¶
func (ec *EventContextV1) SetType(t string) error
SetType implements EventContextWriter.SetType
func (EventContextV1) String ¶
func (ec EventContextV1) String() string
String returns a pretty-printed representation of the EventContext.
func (EventContextV1) Validate ¶
func (ec EventContextV1) Validate() error
Validate returns errors based on requirements from the CloudEvents spec. For more details, see https://github.com/cloudevents/spec/blob/v1.0-rc1/spec.md.
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 // SetDataSchema sets the schema url of the context. SetDataSchema(string) error // SetDataContentType sets the data content type of the context. SetDataContentType(string) error // DeprecatedSetDataContentEncoding sets the data context encoding of the context. DeprecatedSetDataContentEncoding(string) error // SetExtension sets the given interface onto the extension attributes // determined by the provided name. // // This function fails in V1 if the name doesn't respect the regex ^[a-zA-Z0-9]+$ // // Package ./types documents the types that are allowed as extension values. 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 // DataSchema returns event.Context.GetDataSchema(). DataSchema() string // DataContentType returns event.Context.GetDataContentType(). DataContentType() string // DataMediaType returns event.Context.GetDataMediaType(). DataMediaType() string // DeprecatedDataContentEncoding returns event.Context.DeprecatedGetDataContentEncoding(). DeprecatedDataContentEncoding() string // Extensions returns the event.Context.GetExtensions(). // Extensions use the CloudEvents type system, details in package cloudevents/types. Extensions() map[string]interface{} // ExtensionAs returns event.Context.ExtensionAs(name, obj). // // DEPRECATED: Access extensions directly via the e.Extensions() map. // Use functions in the types package to convert extension values. // For example replace this: // // var i int // err := e.ExtensionAs("foo", &i) // // With this: // // i, err := types.ToInteger(e.Extensions["foo"]) // ExtensionAs(string, interface{}) error // Data returns the raw data buffer, it might be encoded depending on data // content type. Data() []byte // DataAs attempts to populate the provided data object with the event payload. // data should be a pointer type. DataAs(interface{}) error }
EventWriter is the interface for reading through an event from attributes.
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) // SetDataSchema performs event.Context.SetDataSchema. SetDataSchema(string) // SetDataContentType performs event.Context.SetDataContentType. SetDataContentType(string) // DeprecatedSetDataContentEncoding performs event.Context.DeprecatedSetDataContentEncoding. SetDataContentEncoding(string) // SetExtension performs event.Context.SetExtension. SetExtension(string, interface{}) // SetData encodes the given payload with the given content type. SetData(string, interface{}) error }
EventWriter is the interface for writing through an event onto attributes. If an error is thrown by a sub-component, EventWriter caches the error internally and exposes errors with a call to event.Validate().
Source Files ¶
- content_type.go
- data_content_encoding.go
- doc.go
- event.go
- event_data.go
- event_interface.go
- event_marshal.go
- event_observability.go
- event_reader.go
- event_writer.go
- eventcontext.go
- eventcontext_v03.go
- eventcontext_v03_reader.go
- eventcontext_v03_writer.go
- eventcontext_v1.go
- eventcontext_v1_reader.go
- eventcontext_v1_writer.go
- extensions.go
Directories ¶
Path | Synopsis |
---|---|
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`. |
text
Text codec converts []byte or string to string and vice-versa.
|
Text codec converts []byte or string to string and vice-versa. |
xml
Package xml holds the encoder/decoder implementation for `application/xml`.
|
Package xml holds the encoder/decoder implementation for `application/xml`. |