event package - github.com/cloudevents/sdk-go/v2/event - Go Packages (original) (raw)
Package event provides primitives to work with CloudEvents specification: https://github.com/cloudevents/spec.
- Constants
- Variables
- func IsExtensionNameValid(key string) bool
- func ReadJson(out *Event, reader io.Reader) error
- func StringOfApplicationCloudEventsBatchJSON() *string
- func StringOfApplicationCloudEventsJSON() *string
- func StringOfApplicationJSON() *string
- func StringOfApplicationXML() *string
- func StringOfBase64() *string
- func StringOfTextPlain() *string
- func WriteJson(in *Event, writer io.Writer) error
- 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) 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) 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() ValidationError
- 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) 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() ValidationError
- type EventContextWriter
- type EventReader
- type EventWriter
- type ValidationError
const ( TextPlain = "text/plain" TextJSON = "text/json" ApplicationJSON = "application/json" ApplicationXML = "application/xml" ApplicationCloudEventsJSON = "application/cloudevents+json" ApplicationCloudEventsBatchJSON = "application/cloudevents-batch+json" )
const (
DataContentEncodingKey = "datacontentencoding"
)
func StringOfApplicationCloudEventsBatchJSON() *string
StringOfApplicationCloudEventsBatchJSON returns a string pointer to "application/cloudevents-batch+json"
func StringOfApplicationCloudEventsJSON() *string
StringOfApplicationCloudEventsJSON returns a string pointer to "application/cloudevents+json"
func StringOfApplicationJSON() *string
StringOfApplicationJSON returns a string pointer to "application/json"
func StringOfApplicationXML() *string
StringOfApplicationXML returns a string pointer to "application/xml"
StringOfBase64 returns a string pointer to "Base64"
func StringOfTextPlain() *string
StringOfTextPlain returns a string pointer to "text/plain"
WriteJson writes the in event in the provided writer. Note: this function assumes the input event is valid.
Event represents the canonical representation of a CloudEvent.
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 (e Event) DataAs(obj interface{}) error
DataAs attempts to populate the provided data object with the event payload. obj should be a pointer type.
func (Event) DataContentType ¶
func (e Event) DataContentType() string
DataContentType implements EventReader.DataContentType
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.
DataSchema implements EventReader.DataSchema
ExtensionAs is 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 (e Event) Extensions() map[string]interface{}
Extensions implements EventReader.Extensions
ID implements EventReader.ID
MarshalJSON implements a custom json marshal method used when this type is marshaled using json.Marshal.
func (e *Event) SetData(contentType string, obj interface{}) error
SetData encodes the given payload with the given content type. If the provided payload is a byte array, when marshalled to json it will be encoded as base64. If the provided payload is different from byte array, datacodec.Encode is invoked to attempt a marshalling to byte array.
func (*Event) SetDataContentEncoding ¶
func (e *Event) SetDataContentEncoding(enc string)
SetDataContentEncoding is deprecated. Implements EventWriter.SetDataContentEncoding.
func (*Event) SetDataContentType ¶
func (e *Event) SetDataContentType(ct string)
SetDataContentType implements EventWriter.SetDataContentType
func (e *Event) SetDataSchema(s string)
SetDataSchema implements EventWriter.SetDataSchema
func (e *Event) SetExtension(name string, obj interface{})
SetExtension implements EventWriter.SetExtension
SetID implements EventWriter.SetID
SetSource implements EventWriter.SetSource
func (e *Event) SetSpecVersion(v string)
SetSpecVersion implements EventWriter.SetSpecVersion
SetSubject implements EventWriter.SetSubject
SetTime implements EventWriter.SetTime
SetType implements EventWriter.SetType
Source implements EventReader.Source
SpecVersion implements EventReader.SpecVersion
String returns a pretty-printed representation of the Event.
Subject implements EventReader.Subject
Time implements EventReader.Time
Type implements EventReader.Type
UnmarshalJSON implements the json unmarshal method used when this type is unmarshaled using json.Unmarshal.
Validate performs a spec based validation on this event. Validation is dependent on the spec version specified in the event context.
EventContext is conical interface for a CloudEvents Context.
type EventContextConverter interface {
AsV03() *[EventContextV03](#EventContextV03)
AsV1() *[EventContextV1](#EventContextV1)
}
EventContextConverter are the methods that allow for event version conversion.
EventContextReader are the methods required to be a reader of context attributes.
type EventContextV03 struct {
Type [string](/builtin#string) `json:"type"`
Source [types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[URIRef](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#URIRef) `json:"source"`
Subject *[string](/builtin#string) `json:"subject,omitempty"`
ID [string](/builtin#string) `json:"id"`
Time *[types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[Timestamp](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#Timestamp) `json:"time,omitempty"`
SchemaURL *[types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[URIRef](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#URIRef) `json:"schemaurl,omitempty"`
DataContentType *[string](/builtin#string) `json:"datacontenttype,omitempty"`
DataContentEncoding *[string](/builtin#string) `json:"datacontentencoding,omitempty"`
Extensions map[[string](/builtin#string)]interface{} `json:"-"`
}
EventContextV03 represents the non-data attributes of a CloudEvents v0.3 event.
func (ec EventContextV03) AsV03() *EventContextV03
AsV03 implements EventContextConverter.AsV03
func (ec EventContextV03) AsV1() *EventContextV1
AsV1 implements EventContextConverter.AsV1
func (ec EventContextV03) Clone() EventContext
Clone implements EventContextConverter.Clone
func (EventContextV03) DeprecatedGetDataContentEncoding ¶
func (ec EventContextV03) DeprecatedGetDataContentEncoding() string
DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding
ExtensionAs implements EventContext.ExtensionAs
func (EventContextV03) GetDataContentType ¶
func (ec EventContextV03) GetDataContentType() string
GetDataContentType implements EventContextReader.GetDataContentType
GetDataMediaType implements EventContextReader.GetDataMediaType
GetDataSchema implements EventContextReader.GetDataSchema
GetExtension implements EventContextReader.GetExtension
func (ec EventContextV03) GetExtensions() map[string]interface{}
GetExtensions implements EventContextReader.GetExtensions
GetID implements EventContextReader.GetID
GetSource implements EventContextReader.GetSource
GetSpecVersion implements EventContextReader.GetSpecVersion
GetSubject implements EventContextReader.GetSubject
GetTime implements EventContextReader.GetTime
GetType implements EventContextReader.GetType
func (*EventContextV03) SetDataContentType ¶
SetDataContentType implements EventContextWriter.SetDataContentType
SetDataSchema implements EventContextWriter.SetDataSchema
SetExtension adds the extension 'name' with value 'value' to the CloudEvents context. This function fails if the name uses a reserved event context key.
SetID implements EventContextWriter.SetID
SetSource implements EventContextWriter.SetSource
SetSubject implements EventContextWriter.SetSubject
SetTime implements EventContextWriter.SetTime
SetType implements EventContextWriter.SetType
String returns a pretty-printed representation of the EventContext.
type EventContextV1 struct {
ID [string](/builtin#string) `json:"id"`
Source [types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[URIRef](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#URIRef) `json:"source"`
Type [string](/builtin#string) `json:"type"`
DataContentType *[string](/builtin#string) `json:"datacontenttype,omitempty"`
Subject *[string](/builtin#string) `json:"subject,omitempty"`
Time *[types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[Timestamp](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#Timestamp) `json:"time,omitempty"`
DataSchema *[types](/github.com/cloudevents/sdk-go/v2@v2.9.0/types).[URI](/github.com/cloudevents/sdk-go/v2@v2.9.0/types#URI) `json:"dataschema,omitempty"`
Extensions map[[string](/builtin#string)]interface{} `json:"-"`
}
EventContextV1 represents the non-data attributes of a CloudEvents v1.0 event.
func (ec EventContextV1) AsV03() *EventContextV03
AsV03 implements EventContextConverter.AsV03
func (ec EventContextV1) AsV1() *EventContextV1
AsV1 implements EventContextConverter.AsV1
func (ec EventContextV1) Clone() EventContext
Clone implements EventContextConverter.Clone
func (EventContextV1) DeprecatedGetDataContentEncoding ¶
func (ec EventContextV1) DeprecatedGetDataContentEncoding() string
DeprecatedGetDataContentEncoding implements EventContextReader.DeprecatedGetDataContentEncoding
ExtensionAs implements EventContext.ExtensionAs
func (EventContextV1) GetDataContentType ¶
func (ec EventContextV1) GetDataContentType() string
GetDataContentType implements EventContextReader.GetDataContentType
GetDataMediaType implements EventContextReader.GetDataMediaType
GetDataSchema implements EventContextReader.GetDataSchema
GetExtension implements EventContextReader.GetExtension
func (ec EventContextV1) GetExtensions() map[string]interface{}
GetExtensions implements EventContextReader.GetExtensions
GetID implements EventContextReader.GetID
GetSource implements EventContextReader.GetSource
GetSpecVersion implements EventContextReader.GetSpecVersion
GetSubject implements EventContextReader.GetSubject
GetTime implements EventContextReader.GetTime
GetType implements EventContextReader.GetType
func (*EventContextV1) SetDataContentType ¶
SetDataContentType implements EventContextWriter.SetDataContentType
SetDataSchema implements EventContextWriter.SetDataSchema
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]+$ or if the name uses a reserved event context key.
SetID implements EventContextWriter.SetID
SetSource implements EventContextWriter.SetSource
SetSubject implements EventContextWriter.SetSubject
SetTime implements EventContextWriter.SetTime
SetType implements EventContextWriter.SetType
String returns a pretty-printed representation of the EventContext.
EventContextWriter are the methods required to be a writer of context attributes.
EventReader is the interface for reading through an event from attributes.
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().