events

package
v1.3.7-yckms.1 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package events provides methods for working with CloudEvents.

Package events

Index

Constants

View Source
const CloudEventsSpecVersion = "1.0"

The version of the CloudEvents specification the package adheres to.

Variables

This section is empty.

Functions

func RegisteredTypes

func RegisteredTypes() map[string]*EventType

RegisteredTypes returns a map of all registered event types. The key is the event type name.

Types

type Event

type Event struct {
	// contains filtered or unexported fields
}

Event is an instance of a certain event type.

func (Event) Attributes

func (e Event) Attributes() map[string]any

Attributes returns the attributes attached to the event. These attributes are optional and this function may return an empty map.

func (Event) ID

func (e Event) ID() string

ID returns the identifier for the event.

func (*Event) MarshalJSON

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

MarshalJSON serializes the event to JSON, following the CloudEvents specification.

func (*Event) MarshalProto

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

MarshalProto serializes the event to the CloudEvents Protobuf wire format.

func (Event) Message

func (e Event) Message() protoreflect.ProtoMessage

Message returns the underlying message (aka data) of the event.

func (*Event) Proto

func (e *Event) Proto() (*pb.CloudEvent, error)

Proto returns the CloudEvents protobuf for the event.

func (Event) Type

func (e Event) Type() *EventType

Type returns the underlying event type.

type EventContentType

type EventContentType string

The content type of an event.

const (
	ContentTypeProtobuf EventContentType = "application/protobuf"
	ContentTypeJSON     EventContentType = "application/json"
)

type EventNotFoundError

type EventNotFoundError struct {
	// contains filtered or unexported fields
}

EventNotFoundError indicates that no matching PubSub provider was found.

func (*EventNotFoundError) Error

func (e *EventNotFoundError) Error() string

type EventType

type EventType struct {
	// contains filtered or unexported fields
}

EventType describes the type of an event.

func Get

func Get(name string) (*EventType, error)

Get returns an event type by name.

func RegisterType

func RegisterType(name, source string, desc protoreflect.MessageDescriptor) *EventType

RegisterType registers a new event type. It is intended for use in init() functions for each event type. It will panic if errors are encountered.

func (EventType) Descriptor

func (t EventType) Descriptor() protoreflect.MessageDescriptor

Descriptor returns the message descriptor for messages of the event type.

func (EventType) Name

func (t EventType) Name() string

Name returns the unique name for the event type.

func (*EventType) New

func (t *EventType) New(id string, msg protoreflect.ProtoMessage, attributes map[string]any) (*Event, error)

New creates a new event of a given type.

The "id" and "msg" parameters are required. The "attributes" parameter supports the following value types:

  • string
  • int
  • bool
  • []byte
  • time.Time

func (EventType) Source

func (t EventType) Source() string

Source returns the source for the event type.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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