shadow

package
v5.0.6 Latest Latest
Warning

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

Go to latest
Published: May 28, 2021 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultOptions = Options{

	IncrementalUpdate: true,
}

DefaultOptions is a default Device Shadow options.

View Source
var ErrIncompatibleMapping = errors.New("unable to convert state to struct")

ErrIncompatibleMapping is returned if state can't be converted into struct.

View Source
var ErrInvalidResponse = errors.New("invalid response from AWS IoT")

ErrInvalidResponse is returned if failed to parse response from AWS IoT.

View Source
var ErrRejected = errors.New("rejected")

ErrRejected is returned if AWS IoT responded on rejected topic.

View Source
var ErrUnsupportedMapKeyType = errors.New("unsupported map key type")

ErrUnsupportedMapKeyType is returned if map key type is not string.

View Source
var ErrVersionConflict = errors.New("version conflict")

ErrVersionConflict means thing state update was aborted due to version conflict.

Functions

This section is empty.

Types

type ErrorResponse

type ErrorResponse struct {
	Code        int    `json:"code"`
	Message     string `json:"message"`
	Timestamp   int64  `json:"timestamp"`
	ClientToken string `json:"clientToken"`
}

ErrorResponse represents error response from AWS IoT.

func (*ErrorResponse) Error

func (e *ErrorResponse) Error() string

Error implements error interface.

type Metadata

type Metadata struct {
	Timestamp int `json:"timestamp"`
}

Metadata represents metadata of state attribute.

type NestedMetadata

type NestedMetadata map[string]interface{}

NestedMetadata is JSON unmarshaller for state metadata.

func (*NestedMetadata) UnmarshalJSON

func (n *NestedMetadata) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type NestedState

type NestedState map[string]interface{}

NestedState is JSON unmarshaller for state metadata.

func (*NestedState) UnmarshalJSON

func (n *NestedState) UnmarshalJSON(b []byte) error

UnmarshalJSON implements json.Unmarshaler.

type Option

type Option func(options *Options) error

Option is a functional option of UpdateJob.

func WithIncrementalUpdate

func WithIncrementalUpdate(enable bool) Option

WithIncrementalUpdate enables increamental update of state document. Enabled by default.

func WithName

func WithName(name string) Option

WithName sets shadow name.

type Options

type Options struct {
	Name              string
	IncrementalUpdate bool
}

Options stores Device Shadow options.

type Shadow

type Shadow interface {
	mqtt.Handler
	// Get thing state and update local state document.
	Get(ctx context.Context) (*ThingDocument, error)
	// Report thing state and update local state document.
	Report(ctx context.Context, state interface{}) (*ThingDocument, error)
	// Desire sets desired thing state and update local state document.
	Desire(ctx context.Context, state interface{}) (*ThingDocument, error)
	// Document returns full thing document.
	Document() *ThingDocument
	// Delete thing shadow.
	Delete(ctx context.Context) error
	// OnDelta sets handler of state deltas.
	OnDelta(func(delta NestedState))
	// OnError sets handler of asynchronous errors.
	OnError(func(error))
}

Shadow is an interface of Thing Shadow.

func New

func New(ctx context.Context, cli awsiotdev.Device, opt ...Option) (Shadow, error)

New creates Thing Shadow interface.

type ThingDocument

type ThingDocument struct {
	State       ThingState         `json:"state"`
	Metadata    ThingStateMetadata `json:"metadata"`
	Version     int                `json:"version,omitempty"`
	Timestamp   int                `json:"timestamp,omitempty"`
	ClientToken string             `json:"clientToken,omitempty"`

	MaybeIncomplete bool `json:"-"`
}

ThingDocument represents Thing Shadow Document.

type ThingState

type ThingState struct {
	Desired  NestedState `json:"desired,omitempty"`
	Reported NestedState `json:"reported,omitempty"`
	Delta    NestedState `json:"delta,omitempty"`
}

ThingState represents Thing Shadow State.

type ThingStateMetadata

type ThingStateMetadata struct {
	Desired  NestedMetadata `json:"desired,omitempty"`
	Reported NestedMetadata `json:"reported,omitempty"`
	Delta    NestedMetadata `json:"delta,omitempty"`
}

ThingStateMetadata represents Thing Shadow State metadata.

Jump to

Keyboard shortcuts

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