Documentation ¶
Index ¶
- Constants
- type Envelope
- func (msg *Envelope) WithExtra(extra interface{}) *Envelope
- func (msg *Envelope) WithFields(fields string) *Envelope
- func (msg *Envelope) WithHeaders(headers *Headers) *Envelope
- func (msg *Envelope) WithPath(path string) *Envelope
- func (msg *Envelope) WithRevision(revision int64) *Envelope
- func (msg *Envelope) WithStatus(status int) *Envelope
- func (msg *Envelope) WithTimestamp(timestamp string) *Envelope
- func (msg *Envelope) WithTopic(topic *Topic) *Envelope
- func (msg *Envelope) WithValue(value interface{}) *Envelope
- type Headers
- func (h *Headers) Clone() *Headers
- func (h *Headers) ContentType() string
- func (h *Headers) CorrelationID() string
- func (h *Headers) ETag() string
- func (h *Headers) Generic(key string) (interface{}, bool)
- func (h *Headers) IfMatch() string
- func (h *Headers) IfNoneMatch() string
- func (h *Headers) MarshalJSON() ([]byte, error)
- func (h *Headers) ReplyTo() string
- func (h *Headers) ResponseRequired() bool
- func (h *Headers) Timeout() time.Duration
- func (h *Headers) UnmarshalJSON(data []byte) error
- func (h *Headers) WithContentType(contentType string) *Headers
- func (h *Headers) WithCorrelationID(correlationID string) *Headers
- func (h *Headers) WithETag(eTag string) *Headers
- func (h *Headers) WithGeneric(key string, value interface{}) *Headers
- func (h *Headers) WithIfMatch(ifMatch string) *Headers
- func (h *Headers) WithIfNoneMatch(ifNoneMatch string) *Headers
- func (h *Headers) WithReplyTo(replyTo string) *Headers
- func (h *Headers) WithResponseRequired(isResponseRequired bool) *Headers
- func (h *Headers) WithTimeout(timeout time.Duration) *Headers
- type Topic
- func (topic *Topic) MarshalJSON() ([]byte, error)
- func (topic *Topic) String() string
- func (topic *Topic) UnmarshalJSON(data []byte) error
- func (topic *Topic) WithAction(action TopicAction) *Topic
- func (topic *Topic) WithChannel(channel TopicChannel) *Topic
- func (topic *Topic) WithCriterion(criterion TopicCriterion) *Topic
- func (topic *Topic) WithEntityID(entityID string) *Topic
- func (topic *Topic) WithGroup(group TopicGroup) *Topic
- func (topic *Topic) WithNamespace(ns string) *Topic
- type TopicAction
- type TopicChannel
- type TopicCriterion
- type TopicGroup
Constants ¶
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" )
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 ¶
WithExtra sets any extra Envelope configurations as defined by the Ditto protocol specification.
func (*Envelope) WithFields ¶
WithFields sets the fields of the Envelope as defined by the Ditto protocol specification.
func (*Envelope) WithHeaders ¶
WithHeaders sets the Headers of the Envelope.
func (*Envelope) WithRevision ¶
WithRevision sets the current revision number of an entity this Envelope refers to.
func (*Envelope) WithStatus ¶
WithStatus sets the Envelope's status based on the HTTP codes available.
func (*Envelope) WithTimestamp ¶
WithTimestamp sets the timestamp 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 (*Headers) ContentType ¶
ContentType returns the 'content-type' header value or empty string if not set.
func (*Headers) CorrelationID ¶
CorrelationID returns the 'correlation-id' header value or empty string if not set.
func (*Headers) Generic ¶
Generic returns the value of the provided key header and if a header with such key is present.
func (*Headers) IfNoneMatch ¶
IfNoneMatch returns the 'if-none-match' header value or empty string if not set.
func (*Headers) MarshalJSON ¶
MarshalJSON returns the JSON encoding of all headers.
func (*Headers) ResponseRequired ¶
ResponseRequired returns 'true' if the 'response-required' header is set, otherwise 'false'.
func (*Headers) Timeout ¶
Timeout returns the 'timeout' header value or duration of 60 seconds if not set.
func (*Headers) UnmarshalJSON ¶
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 ¶
WithContentType sets the 'content-type' header value if non-empty contentType is provided, otherwise removes the 'content-type' header.
func (*Headers) WithCorrelationID ¶
WithCorrelationID sets the 'correlation-id' header value if non-empty correlationID is provided, otherwise removes the 'correlation-id' header.
func (*Headers) WithETag ¶
WithETag sets the 'etag' header value if non-empty etag is provided, otherwise removes the 'etag' header.
func (*Headers) WithGeneric ¶
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 ¶
WithIfMatch sets the 'if-match' header value if non-empty ifMatch is provided, otherwise removes the 'if-match' header.
func (*Headers) WithIfNoneMatch ¶
WithIfNoneMatch sets the 'if-none-match' header value if non-empty ifNoneMatch is provided, otherwise removes the 'if-none-match' header.
func (*Headers) WithReplyTo ¶
WithReplyTo sets the 'reply-to' header value if non-empty replyTo is provided, otherwise removes the 'reply-to' header.
func (*Headers) WithResponseRequired ¶
WithResponseRequired sets the 'response-required' header value if 'true' value is provided, otherwise removes the 'response-required' header.
func (*Headers) WithTimeout ¶
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 ¶
MarshalJSON marshals topic value.
func (*Topic) UnmarshalJSON ¶
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 ¶
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 ¶
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.