events

package
v0.1.18 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CloudEventsVersion defines version of CloudEvent specification used in Dispatch
	CloudEventsVersion = "0.1"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudEvent added in v0.1.13

type CloudEvent struct {
	// Event context
	// Mandatory, e.g. "com.vmware.vsphere"
	Namespace string `json:"namespace" validate:"required"`
	// Mandatory, e.g. "user.created"
	EventType string `json:"event-type" validate:"required,max=128,eventtype"`
	// Optional, e.g. "VMODL6.5"
	EventTypeVersion string `json:"event-type-version,omitempty" validate:"omitempty,min=1"`
	// Mandatory, fixed to "0.1"
	CloudEventsVersion string `json:"cloud-events-version" validate:"eq=0.1"`
	// Mandatory, e.g. "vcenter"
	SourceType string `json:"source-type" validate:"required,max=32"`
	// Mandatory, e.g. "vcenter1.corp.local"
	SourceID string `json:"source-id" validate:"required,max=64"`
	// Mandatory, e.g. UUID or "43252363". Must be unique for this Source
	EventID string `json:"event-id" validate:"required"`
	// Optional, Timestamp in RFC 3339 format, e.g. "1985-04-12T23:20:50.52Z"
	EventTime time.Time `json:"event-time,omitempty" validate:"-"`
	// Optional, if specified must be a valid URI
	SchemaURL string `json:"schema-url,omitempty" validate:"omitempty,uri"`
	// Optional, if specified must be a valid mime type, e.g. "application/json"
	ContentType string `json:"content-type,omitempty" validate:"omitempty,min=1"`
	// Optional, key-value dictionary for use by Dispatch
	Extensions CloudEventExtensions `json:"extensions,omitempty" validate:"omitempty,min=1"`

	// Event payload
	Data string `json:"data" validate:"omitempty"`
}

CloudEvent structure implements CloudEvent spec: https://github.com/cloudevents/spec/blob/b0124528486d3f6b9a247cadd68d91b44b3d3ef4/spec.md

func NewCloudEventWithDefaults added in v0.1.13

func NewCloudEventWithDefaults(eventType string) CloudEvent

NewCloudEventWithDefaults creates new copy of CloudEvent struct, using reasonable defaults for all mandatory attributes, requiring only eventType to be explicitly specified.

func (*CloudEvent) DefaultTopic added in v0.1.13

func (e *CloudEvent) DefaultTopic() string

DefaultTopic returns a default representation of topic for messaging purposes.

func (*CloudEvent) ExtractSpan added in v0.1.13

func (e *CloudEvent) ExtractSpan() (opentracing.SpanContext, error)

ExtractSpan extracts OpenTracing Span from a CloudEvent.

func (*CloudEvent) InjectSpan added in v0.1.13

func (e *CloudEvent) InjectSpan(span opentracing.Span) error

InjectSpan injects OpenTracing Span into a CloudEvent.

type CloudEventExtensions added in v0.1.13

type CloudEventExtensions map[string]interface{}

CloudEventExtensions holds attributes for CloudEvent that are not part of the standard.

func (CloudEventExtensions) ForeachKey added in v0.1.13

func (ex CloudEventExtensions) ForeachKey(handler func(key, val string) error) error

ForeachKey conforms to the opentracing TextMapReader interface.

func (CloudEventExtensions) Set added in v0.1.13

func (ex CloudEventExtensions) Set(key, val string)

Set implements Set() of opentracing.TextMapWriter.

type Handler

type Handler func(context.Context, *CloudEvent)

Handler is a callback function used to handle received event

type StreamParser added in v0.1.13

type StreamParser interface {
	Parse(io.Reader) ([]CloudEvent, error)
}

StreamParser takes io.Reader and returns slice of CloudEvents. It is up to the implementation whether incorrect CloudEvent should be omitted from slice, or error should be returned. If error is returned, events slice is expected to be nil.

type Subscription

type Subscription interface {
	GetTopic() string
	Unsubscribe() error
	GetOrganization() string
}

Subscription represents an active subscription within Transport. Subscription can be stopped by calling Unsubscribe()

type Transport added in v0.1.13

type Transport interface {

	// Publish publishes the event using the underlying transport
	Publish(ctx context.Context, event *CloudEvent, topic string, organization string) error

	// Subscribe takes a handler to run on every event received on topic. Returns a cancelable Subscription
	Subscribe(ctx context.Context, topic string, organization string, handler Handler) (Subscription, error)
	Close()
}

Transport is an abstraction over possible implementation of messaging

type Validator added in v0.1.13

type Validator interface {
	Validate(event *CloudEvent) error
}

Validator takes a CloudEvent and validates it. Although CloudEvent struct includes tags following go-playground/validator convention, validation schema is up to the implementation.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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