spec

package
v2.15.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2024 License: Apache-2.0 Imports: 5 Imported by: 26

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

View Source
var (
	VS  *Versions
	V03 Version
	V1  Version
)

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() with prefix
	PrefixedName() string
	// 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(event.EventContextReader) interface{}
	// Set the value of this attribute on an event context
	Set(event.EventContextWriter, interface{}) error
	// Delete this attribute from and event context, when possible
	Delete(event.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.

const (
	// Required cloudevents attributes
	ID Kind = iota
	Source
	SpecVersion
	Type
	// Optional cloudevents attributes
	DataContentType
	DataSchema
	Subject
	Time
)

func (Kind) IsRequired

func (k Kind) IsRequired() bool

IsRequired returns true for attributes defined as "required" by the CE spec.

func (Kind) String

func (k Kind) String() string

String is a human-readable string, for a valid attribute name use Attribute.Name

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(prefixedName string) Attribute
	// Attribute looks up the attribute from kind.
	// Returns nil if not found.
	AttributeFromKind(kind Kind) Attribute
	// Attributes returns all the context attributes for this version.
	Attributes() []Attribute
	// Convert translates a context to this version.
	Convert(event.EventContextConverter) event.EventContext
	// NewContext returns a new context for this version.
	NewContext() event.EventContext
	// SetAttribute sets named attribute to value.
	//
	// Name is case insensitive.
	// Does nothing if name does not start with prefix.
	SetAttribute(context event.EventContextWriter, name string, value interface{}) error
}

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 New

func New() *Versions

New returns a set of versions

func WithPrefix

func WithPrefix(prefix string) *Versions

WithPrefix returns a set of versions with prefix added to all attribute names.

func WithPrefixMatchExact

func WithPrefixMatchExact(attributeNameMatchMapper func(string) string, prefix string) *Versions

WithPrefixMatchExact returns a set of versions with prefix added to all attribute names.

func (*Versions) Latest

func (vs *Versions) Latest() Version

Latest returns the latest Version

func (*Versions) Prefix

func (vs *Versions) Prefix() string

Prefix is the lowercase attribute name prefix.

func (*Versions) PrefixedSpecVersionName

func (vs *Versions) PrefixedSpecVersionName() string

PrefixedSpecVersionName returns the specversion attribute PrefixedName

func (*Versions) Version

func (vs *Versions) Version(name string) Version

Version returns the named version.

func (*Versions) Versions

func (vs *Versions) Versions() []Version

Versions returns the list of all known versions, most recent first.

Jump to

Keyboard shortcuts

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