protocol

package
v0.1.0-M4 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2023 License: Apache-2.0, EPL-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ContentTypeDitto defines the Ditto JSON 'content-type' header value for Ditto Protocol messages.
	ContentTypeDitto = "application/vnd.eclipse.ditto+json"

	// ContentTypeJSON defines the JSON 'content-type' header value for Ditto Protocol messages.
	ContentTypeJSON = "application/json"

	// ContentTypeJSONMerge defines the JSON merge patch 'content-type' header value for Ditto Protocol messages,
	// as specified with RFC 7396 (https://datatracker.ietf.org/doc/html/rfc7396).
	ContentTypeJSONMerge = "application/merge-patch+json"
)
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     json.RawMessage `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.

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 Headers

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

Headers represents currently used Ditto headers along with additional HTTP headers that can be applied depending on the transport used. All protocol defined headers are case-insensitive and by default lowercase is used. See https://www.eclipse.org/ditto/protocol-specification.html

func NewHeaders

func NewHeaders() *Headers

NewHeaders creates an instance with no headers set.

func (*Headers) Clone

func (h *Headers) Clone() *Headers

Clone creates a new instance with all headers copied.

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(key string) (interface{}, bool)

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) MarshalJSON

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

MarshalJSON returns the JSON encoding of all headers.

func (*Headers) ReplyTo

func (h *Headers) ReplyTo() string

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

func (*Headers) ResponseRequired

func (h *Headers) ResponseRequired() bool

ResponseRequired returns 'true' if the 'response-required' header is set, otherwise 'false'.

func (*Headers) Timeout

func (h *Headers) Timeout() time.Duration

Timeout returns the 'timeout' header value or duration of 60 seconds if not set.

func (*Headers) UnmarshalJSON

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

UnmarshalJSON parses the JSON-encoded data and initializes the headers with the result. Error is returned if there is unexpected data format or if the data contains an invalid string representation of timeout header value.

The timeout should be a non-negative value and unit symbol (ms, s or m), e.g. '45s' or '250ms' or '1m'. If the unit symbol is not provided, the value is interpreted as provided in seconds.

func (*Headers) WithContentType

func (h *Headers) WithContentType(contentType string) *Headers

WithContentType sets the 'content-type' header value if non-empty contentType is provided, otherwise removes the 'content-type' header.

func (*Headers) WithCorrelationID

func (h *Headers) WithCorrelationID(correlationID string) *Headers

WithCorrelationID sets the 'correlation-id' header value if non-empty correlationID is provided, otherwise removes the 'correlation-id' header.

func (*Headers) WithETag

func (h *Headers) WithETag(eTag string) *Headers

WithETag sets the 'etag' header value if non-empty etag is provided, otherwise removes the 'etag' header.

func (*Headers) WithGeneric

func (h *Headers) WithGeneric(key string, value interface{}) *Headers

WithGeneric sets the value of the provided key header. If nil or empty string is provided, the header with the provided key is removed.

func (*Headers) WithIfMatch

func (h *Headers) WithIfMatch(ifMatch string) *Headers

WithIfMatch sets the 'if-match' header value if non-empty ifMatch is provided, otherwise removes the 'if-match' header.

func (*Headers) WithIfNoneMatch

func (h *Headers) WithIfNoneMatch(ifNoneMatch string) *Headers

WithIfNoneMatch sets the 'if-none-match' header value if non-empty ifNoneMatch is provided, otherwise removes the 'if-none-match' header.

func (*Headers) WithReplyTo

func (h *Headers) WithReplyTo(replyTo string) *Headers

WithReplyTo sets the 'reply-to' header value if non-empty replyTo is provided, otherwise removes the 'reply-to' header.

func (*Headers) WithResponseRequired

func (h *Headers) WithResponseRequired(isResponseRequired bool) *Headers

WithResponseRequired sets the 'response-required' header value if 'true' value is provided, otherwise removes the 'response-required' header.

func (*Headers) WithTimeout

func (h *Headers) WithTimeout(timeout time.Duration) *Headers

WithTimeout sets the 'timeout' header value.

The provided value should be a non-negative duration in Millisecond, Second or Minute unit. The change results in timeout header string value containing the duration and the unit symbol (ms, s or m), e.g. '45s' or '250ms' or '1m'.

The default value is '60s'. If a negative duration or duration of an hour or more is provided, the timeout header value is removed, i.e. the default one is used.

type Topic

type Topic struct {
	Namespace string
	EntityID  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>/<entityID>/<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 value.

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 value.

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) WithEntityID

func (topic *Topic) WithEntityID(entityID string) *Topic

WithEntityID configures the entity ID 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   TopicGroup = "things"
	GroupPolicies TopicGroup = "policies"
)

Group constants.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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