Documentation ¶
Overview ¶
Package spec provides spec-version metadata.
For use by code that maps events using (prefixed) attribute name strings. Supports handling multiple spec versions uniformly.
Index ¶
Constants ¶
This section is empty.
Variables ¶
Built-in un-prefixed versions.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
type Attribute interface { Kind() Kind // Name of the attribute with respect to the current spec Version() Name() string // Version of the spec that this attribute belongs to Version() Version // Get the value of this attribute from an event context Get(ce.EventContextReader) interface{} // Set the value of this attribute on an event context Set(ce.EventContextWriter, interface{}) error // Delete this attribute from and event context, when possible Delete(ce.EventContextWriter) error }
Attribute is a named attribute accessor. The attribute name is specific to a Version.
type Kind ¶
type Kind uint8
Kind is a version-independent identifier for a CloudEvent context attribute.
func (Kind) IsRequired ¶
IsRequired returns true for attributes defined as "required" by the CE spec.
type Version ¶
type Version interface { // String name of the version, e.g. "1.0" String() string // Prefix for attribute names. Prefix() string // Attribute looks up a prefixed attribute name (case insensitive). // Returns nil if not found. Attribute(name string) Attribute // Attributes returns all the context attributes for this version. Attributes() []Attribute // NewContext returns a new context for this version. NewContext() ce.EventContext // Convert translates a context to this version. Convert(ce.EventContextConverter) ce.EventContext // SetAttribute sets named attribute to value. // // Name is case insensitive. // Does nothing if name does not start with prefix. SetAttribute(context ce.EventContextWriter, name string, value interface{}) error // Attribute looks up the attribute from kind. // Returns nil if not found. AttributeFromKind(kind Kind) Attribute }
Version provides meta-data for a single spec-version.
type Versions ¶
type Versions struct {
// contains filtered or unexported fields
}
Versions contains all known versions with the same attribute prefix.
func WithPrefix ¶
WithPrefix returns a set of versions with prefix added to all attribute names.
func (*Versions) FindVersion ¶ added in v0.10.1
FindVersion calls getAttr with known (prefixed) spec-version attribute names till it finds a valid version.
func (*Versions) SpecVersionNames ¶
SpecVersionNames returns distinct names of the specversion attribute used in all versions, newest first. Names are prefixed.