protocol

package
v0.0.0-...-3e6e175 Latest Latest
Warning

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

Go to latest
Published: May 4, 2023 License: EPL-2.0 Imports: 5 Imported by: 14

Documentation

Index

Constants

View Source
const (
	HeaderCorrelationID    = "correlation-id"
	HeaderResponseRequired = "response-required"
	HeaderChannel          = "ditto-channel"
	HeaderDryRun           = "ditto-dry-run"
	HeaderOrigin           = "origin"
	HeaderOriginator       = "ditto-originator"
	HeaderETag             = "ETag"
	HeaderIfMatch          = "If-Match"
	HeaderIfNoneMatch      = "If-None-Match"
	HeaderReplyTarget      = "ditto-reply-target"
	HeaderReplyTo          = "reply-to"
	HeaderTimeout          = "timeout"
	HeaderSchemaVersion    = "version"
	HeaderContentType      = "content-type"
)

Ditto-specific headers constants.

View Source
const TopicPlaceholder = "_"

TopicPlaceholder can be used in the context of "any" for things namespaces and IDs in the retrieve topics.

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope

type Envelope struct {
	Topic     *Topic      `json:"topic"`
	Headers   *Headers    `json:"headers,omitempty"`
	Path      string      `json:"path"`
	Value     interface{} `json:"value,omitempty"`
	Fields    string      `json:"fields,omitempty"`
	Extra     interface{} `json:"extra,omitempty"`
	Status    int         `json:"status,omitempty"`
	Revision  int64       `json:"revision,omitempty"`
	Timestamp string      `json:"timestamp,omitempty"`
}

Envelope represents the Ditto's Envelope specification. As a Ditto's message consists of an envelope along with a Ditto-compliant payload, the structure is to be used as a ready to use Ditto message.

func (*Envelope) WithExtra

func (msg *Envelope) WithExtra(extra interface{}) *Envelope

WithExtra sets any extra Envelope configurations as defined by the Ditto protocol specification.

func (*Envelope) WithFields

func (msg *Envelope) WithFields(fields string) *Envelope

WithFields sets the fields of the Envelope as defined by the Ditto protocol specification.

func (*Envelope) WithHeaders

func (msg *Envelope) WithHeaders(headers *Headers) *Envelope

WithHeaders sets the Headers of the Envelope.

func (*Envelope) WithPath

func (msg *Envelope) WithPath(path string) *Envelope

WithPath sets the Ditto path of the Envelope.

func (*Envelope) WithRevision

func (msg *Envelope) WithRevision(revision int64) *Envelope

WithRevision sets the current revision number of an entity this Envelope refers to.

func (*Envelope) WithStatus

func (msg *Envelope) WithStatus(status int) *Envelope

WithStatus sets the Envelope's status based on the HTTP codes available.

func (*Envelope) WithTimestamp

func (msg *Envelope) WithTimestamp(timestamp string) *Envelope

WithTimestamp sets the timestamp of the Envelope.

func (*Envelope) WithTopic

func (msg *Envelope) WithTopic(topic *Topic) *Envelope

WithTopic sets the topic of the Envelope.

func (*Envelope) WithValue

func (msg *Envelope) WithValue(value interface{}) *Envelope

WithValue sets the Ditto value of the Envelope.

type HeaderOpt

type HeaderOpt func(headers *Headers) error

HeaderOpt represents a specific Headers option that can be applied to the Headers instance resulting in changing the value of a specific header of a set of headers.

func WithChannel

func WithChannel(channel string) HeaderOpt

WithChannel sets the 'ditto-channel' header value.

func WithContentType

func WithContentType(contentType string) HeaderOpt

WithContentType sets the 'content-type' header value.

func WithCorrelationID

func WithCorrelationID(correlationID string) HeaderOpt

WithCorrelationID sets the 'correlation-id' header value.

func WithDryRun

func WithDryRun(isDryRun bool) HeaderOpt

WithDryRun sets the 'ditto-dry-run' header value.

func WithETag

func WithETag(eTag string) HeaderOpt

WithETag sets the 'ETag' header value.

func WithGeneric

func WithGeneric(headerID string, value interface{}) HeaderOpt

WithGeneric sets the value of the provided key header.

func WithIfMatch

func WithIfMatch(ifMatch string) HeaderOpt

WithIfMatch sets the 'If-Match' header value.

func WithIfNoneMatch

func WithIfNoneMatch(ifNoneMatch string) HeaderOpt

WithIfNoneMatch sets the 'If-None-Match' header value.

func WithOrigin

func WithOrigin(origin string) HeaderOpt

WithOrigin sets the 'origin' header value.

func WithOriginator

func WithOriginator(dittoOriginator string) HeaderOpt

WithOriginator sets the 'ditto-originator' header value.

func WithReplyTarget

func WithReplyTarget(replyTarget string) HeaderOpt

WithReplyTarget sets the 'ditto-reply-target' header value.

func WithReplyTo

func WithReplyTo(replyTo string) HeaderOpt

WithReplyTo sets the 'reply-to' header value.

func WithResponseRequired

func WithResponseRequired(isResponseRequired bool) HeaderOpt

WithResponseRequired sets the 'response-required' header value.

func WithSchemaVersion

func WithSchemaVersion(schemaVersion string) HeaderOpt

WithSchemaVersion sets the 'version' header value.

func WithTimeout

func WithTimeout(timeout string) HeaderOpt

WithTimeout sets the 'timeout' header value.

type Headers

type Headers struct {
	Values map[string]interface{}
}

Headers represents all Ditto-specific headers along with additional HTTP/etc. headers that can be applied depending on the transport used. See https://www.eclipse.org/ditto/protocol-specification.html

func NewHeaders

func NewHeaders(opts ...HeaderOpt) *Headers

NewHeaders returns a new Headers instance.

func NewHeadersFrom

func NewHeadersFrom(orig *Headers, opts ...HeaderOpt) *Headers

NewHeadersFrom returns a new Headers instance using the provided header.

func (*Headers) Channel

func (h *Headers) Channel() string

Channel returns the 'ditto-channel' header value or empty string if not set.

func (*Headers) ContentType

func (h *Headers) ContentType() string

ContentType returns the 'content-type' header value or empty string if not set.

func (*Headers) CorrelationID

func (h *Headers) CorrelationID() string

CorrelationID returns the 'correlation-id' header value or empty string if not set.

func (*Headers) ETag

func (h *Headers) ETag() string

ETag returns the 'ETag' header value or empty string if not set.

func (*Headers) Generic

func (h *Headers) Generic(id string) interface{}

Generic returns the value of the provided key header and if a header with such key is present.

func (*Headers) IfMatch

func (h *Headers) IfMatch() string

IfMatch returns the 'If-Match' header value or empty string if not set.

func (*Headers) IfNoneMatch

func (h *Headers) IfNoneMatch() string

IfNoneMatch returns the 'If-None-Match' header value or empty string if not set.

func (*Headers) IsDryRun

func (h *Headers) IsDryRun() bool

IsDryRun returns the 'ditto-dry-run' header value or empty string if not set.

func (*Headers) IsResponseRequired

func (h *Headers) IsResponseRequired() bool

IsResponseRequired returns the 'response-required' header value or empty string if not set.

func (*Headers) MarshalJSON

func (h *Headers) MarshalJSON() ([]byte, error)

MarshalJSON marshels Headers.

func (*Headers) Origin

func (h *Headers) Origin() string

Origin returns the 'origin' header value or empty string if not set.

func (*Headers) Originator

func (h *Headers) Originator() string

Originator returns the 'ditto-originator' header value or empty string if not set.

func (*Headers) ReplyTarget

func (h *Headers) ReplyTarget() int64

ReplyTarget returns the 'ditto-reply-target' header value or empty string if not set.

func (*Headers) ReplyTo

func (h *Headers) ReplyTo() string

ReplyTo returns the 'reply-to' header value or empty string if not set.

func (*Headers) Timeout

func (h *Headers) Timeout() string

Timeout returns the 'timeout' header value or empty string if not set.

func (*Headers) UnmarshalJSON

func (h *Headers) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshels Headers.

func (*Headers) Version

func (h *Headers) Version() int64

Version returns the 'version' header value or empty string if not set.

type Topic

type Topic struct {
	Namespace  string
	EntityName string
	Group      TopicGroup
	Channel    TopicChannel
	Criterion  TopicCriterion
	Action     TopicAction
}

Topic represents the Ditto protocol's Topic entity. It's represented in the form of: <namespace>/<entity-name>/<group>/<channel>/<criterion>/<action>. Each of the components is configurable based on the Ditto's specification for the specific group and/or channel/criterion/etc.

func (*Topic) MarshalJSON

func (topic *Topic) MarshalJSON() ([]byte, error)

MarshalJSON marshals Topic.

func (*Topic) String

func (topic *Topic) String() string

String provides the string representation of a Topic entity.

func (*Topic) UnmarshalJSON

func (topic *Topic) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals Topic.

func (*Topic) WithAction

func (topic *Topic) WithAction(action TopicAction) *Topic

WithAction configures the TopicAction of the Topic.

func (*Topic) WithChannel

func (topic *Topic) WithChannel(channel TopicChannel) *Topic

WithChannel configures the TopicChannel of the Topic.

func (*Topic) WithCriterion

func (topic *Topic) WithCriterion(criterion TopicCriterion) *Topic

WithCriterion configures the TopicCriterion of the Topic.

func (*Topic) WithEntityName

func (topic *Topic) WithEntityName(entityName string) *Topic

WithEntityName configures the entity name of the Topic.

func (*Topic) WithGroup

func (topic *Topic) WithGroup(group TopicGroup) *Topic

WithGroup configures the TopicGroup of the Topic.

func (*Topic) WithNamespace

func (topic *Topic) WithNamespace(ns string) *Topic

WithNamespace configures the namespace of the Topic.

type TopicAction

type TopicAction string

TopicAction is a representation of the defined by Ditto topic action options.

const (
	ActionCreate    TopicAction = "create"
	ActionCreated   TopicAction = "created"
	ActionModify    TopicAction = "modify"
	ActionModified  TopicAction = "modified"
	ActionMerge     TopicAction = "merge"
	ActionMerged    TopicAction = "merged"
	ActionDelete    TopicAction = "delete"
	ActionDeleted   TopicAction = "deleted"
	ActionRetrieve  TopicAction = "retrieve"
	ActionSubscribe TopicAction = "subscribe"
	ActionRequest   TopicAction = "request"
	ActionCancel    TopicAction = "cancel"
	ActionNext      TopicAction = "next"
	ActionComplete  TopicAction = "complete"
	ActionFailed    TopicAction = "failed"
)

Action constants.

type TopicChannel

type TopicChannel string

TopicChannel is a representation of the defined by Ditto topic channel options.

const (
	// ChannelTwin represents the twin channel topic.
	ChannelTwin TopicChannel = "twin"
	// ChannelLive represents the live channel topic.
	ChannelLive TopicChannel = "live"
)

type TopicCriterion

type TopicCriterion string

TopicCriterion is a representation of the defined by Ditto topic criterion options.

const (
	// CriterionCommands represents the commands topic criterion.
	CriterionCommands TopicCriterion = "commands"
	// CriterionEvents represents the events topic criterion.
	CriterionEvents TopicCriterion = "events"
	// CriterionSearch represents the search topic criterion.
	CriterionSearch TopicCriterion = "search"
	// CriterionMessages represents the messages topic criterion.
	CriterionMessages TopicCriterion = "messages"
	// CriterionErrors represents the errors topic criterion.
	CriterionErrors TopicCriterion = "errors"
)

type TopicGroup

type TopicGroup string

TopicGroup is a representation of the defined by Ditto topic group options.

const (
	// GroupThings represents the things group in the topic path.
	GroupThings TopicGroup = "things"
	// GroupPolicies represents the policies group in the topic path.
	GroupPolicies TopicGroup = "policies"
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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