model

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: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DefinitionID

type DefinitionID struct {
	Namespace string
	Name      string
	Version   string
}

DefinitionID represents an ID of a given definition entity. Compliant with the Ditto specification it consists of a namespace, name and a version in the form of 'namespace:name:version'. The DefinitionID is used to declare a Thing's model also it is used in declare the different models a Feature represents via its properties.

func NewDefinitionID

func NewDefinitionID(namespace string, name string, version string) *DefinitionID

NewDefinitionID creates a new DefinitionID instance with the namespace, name and version provided. Returns nil if the provided string doesn't match the form.

func NewDefinitionIDFrom

func NewDefinitionIDFrom(full string) *DefinitionID

NewDefinitionIDFrom creates a new DefinitionID instance from a provided string in the form of 'namespace:name:version'. Returns nil if the provided string doesn't match the form.

func (*DefinitionID) MarshalJSON

func (definitionID *DefinitionID) MarshalJSON() ([]byte, error)

MarshalJSON marshals DefinitionID.

func (*DefinitionID) String

func (definitionID *DefinitionID) String() string

String provides the string representation of a DefinitionID in the Ditto's specified form of 'namespace:name:version'.

func (*DefinitionID) UnmarshalJSON

func (definitionID *DefinitionID) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals DefinitionID.

func (*DefinitionID) WithName

func (definitionID *DefinitionID) WithName(name string) *DefinitionID

WithName sets the provided name to the current DefinitionID instance.

func (*DefinitionID) WithNamespace

func (definitionID *DefinitionID) WithNamespace(namespace string) *DefinitionID

WithNamespace sets the provided namespace to the current DefinitionID instance.

func (*DefinitionID) WithVersion

func (definitionID *DefinitionID) WithVersion(version string) *DefinitionID

WithVersion sets the provided version to the current DefinitionID instance.

type Feature

type Feature struct {
	Definition        []*DefinitionID        `json:"definition,omitempty"`
	Properties        map[string]interface{} `json:"properties,omitempty"`
	DesiredProperties map[string]interface{} `json:"desiredProperties,omitempty"`
}

Feature represents the Feature entity defined by the Ditto's Things specification. It is used to manage all data and functionality of a Thing that can be clustered in an outlined technical context.

func (*Feature) WithDefinition

func (feature *Feature) WithDefinition(definition ...*DefinitionID) *Feature

WithDefinition sets the definition of the current Feature instance to the provided set of DefinitionIDs.

func (*Feature) WithDefinitionFrom

func (feature *Feature) WithDefinitionFrom(definition ...string) *Feature

WithDefinitionFrom is an auxiliary method to set the Feature's definition from an array of strings converted into the proper DefinitionID instances.

func (*Feature) WithDesiredProperties

func (feature *Feature) WithDesiredProperties(properties map[string]interface{}) *Feature

WithDesiredProperties sets all desired properties of the current Feature instance.

func (*Feature) WithDesiredProperty

func (feature *Feature) WithDesiredProperty(id string, value interface{}) *Feature

WithDesiredProperty sets/adds a desired property to the current Feature instance.

func (*Feature) WithProperties

func (feature *Feature) WithProperties(properties map[string]interface{}) *Feature

WithProperties sets all properties of the current Feature instance.

func (*Feature) WithProperty

func (feature *Feature) WithProperty(id string, value interface{}) *Feature

WithProperty sets/adds a property to the current Feature instance.

type NamespacedID

type NamespacedID struct {
	Namespace string
	Name      string
}

NamespacedID represents the namespaced ID defined by the Ditto specification. It is a unique identifier representing a Thing compliant with the Ditto requirements: - namespace and name separated by a : (colon) - have a maximum length of 256 characters.

func NewNamespacedID

func NewNamespacedID(namespace string, name string) *NamespacedID

NewNamespacedID creates a new NamespacedID instance using the provided namespace and name. Returns nil if the provided string doesn't match the form.

func NewNamespacedIDFrom

func NewNamespacedIDFrom(full string) *NamespacedID

NewNamespacedIDFrom creates a new NamespacedID instance using the provided string in the valid form of 'namespace:name'. Returns nil if the provided string doesn't match the form.

func (*NamespacedID) MarshalJSON

func (nsID *NamespacedID) MarshalJSON() ([]byte, error)

MarshalJSON marshals NamespacedID.

func (*NamespacedID) String

func (nsID *NamespacedID) String() string

String provides the string representation of the NamespacedID entity in the form of 'namespace:name'.

func (*NamespacedID) UnmarshalJSON

func (nsID *NamespacedID) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals NamespacedID.

func (*NamespacedID) WithName

func (nsID *NamespacedID) WithName(name string) *NamespacedID

WithName sets the provided name to the current NamespacedID instance.

func (*NamespacedID) WithNamespace

func (nsID *NamespacedID) WithNamespace(namespace string) *NamespacedID

WithNamespace sets the provided namespace to the current NamespacedID instance.

type Thing

type Thing struct {
	ID           *NamespacedID          `json:"thingId"`
	PolicyID     *NamespacedID          `json:"policyId,omitempty"`
	DefinitionID *DefinitionID          `json:"definitionId,omitempty"`
	Attributes   map[string]interface{} `json:"attributes,omitempty"`
	Features     map[string]*Feature    `json:"features,omitempty"`
	Revision     int64                  `json:"revision,omitempty"`
	Timestamp    string                 `json:"timestamp,omitempty"`
}

Thing represents the Thing entity model form the Ditto's specification. Things are very generic entities and are mostly used as a “handle” for multiple features belonging to this Thing.

func (*Thing) WithAttribute

func (thing *Thing) WithAttribute(id string, value interface{}) *Thing

WithAttribute sets/add an attribute to the current Thing instance.

func (*Thing) WithAttributes

func (thing *Thing) WithAttributes(attrs map[string]interface{}) *Thing

WithAttributes sets all attributes to the current Thing instance.

func (*Thing) WithDefinition

func (thing *Thing) WithDefinition(definitionID *DefinitionID) *Thing

WithDefinition sets the current Thing instance's definition to the provided value.

func (*Thing) WithDefinitionFrom

func (thing *Thing) WithDefinitionFrom(definitionID string) *Thing

WithDefinitionFrom is an auxiliary method to set the current Thing instance's definition to the provided one in the form of 'namespace:name:version'.

func (*Thing) WithFeature

func (thing *Thing) WithFeature(id string, value *Feature) *Thing

WithFeature sets/adds a Feature to the current features set of the Thing instance.

func (*Thing) WithFeatures

func (thing *Thing) WithFeatures(features map[string]*Feature) *Thing

WithFeatures sets all features to the current Thing instance.

func (*Thing) WithID

func (thing *Thing) WithID(id *NamespacedID) *Thing

WithID sets the provided NamespacedID as the current Thing's instance ID value.

func (*Thing) WithIDFrom

func (thing *Thing) WithIDFrom(id string) *Thing

WithIDFrom is an auxiliary method that sets the ID value of the current Thing instance based on the provided string n the form of 'namespace:name'.

func (*Thing) WithPolicyID

func (thing *Thing) WithPolicyID(policyID *NamespacedID) *Thing

WithPolicyID sets the provided Policy ID to the current Thing instance.

func (*Thing) WithPolicyIDFrom

func (thing *Thing) WithPolicyIDFrom(policyID string) *Thing

WithPolicyIDFrom is an auxiliary method that sets the Policy ID of the current Thing instance from a string NamespacedID representation in the form of 'namespace:name'.

Jump to

Keyboard shortcuts

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