/
metadata.go
58 lines (47 loc) · 1.39 KB
/
metadata.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package iotshadow
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
ThingName string `md:"thingName,required"` // The name of the "thing" in AWS IoT
Op string `md:"op,required,allowed(get,update,delete)"` // The AWS IoT shadow operation to perform
Region string `md:"region"` // The AWS region, uses environment setting by default
}
type Input struct {
Desired map[string]interface{} `md:"desired"` // The desired state of the thing
Reported map[string]interface{} `md:"reported"` // The reported state of the thing
}
type Output struct {
Result map[string]interface{} `md:"result"` // The response shadow document
}
func (i *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"desired": i.Desired,
"reported": i.Reported,
}
}
func (i *Input) FromMap(values map[string]interface{}) error {
var err error
i.Desired, err = coerce.ToObject(values["desired"])
if err != nil {
return err
}
i.Reported, err = coerce.ToObject(values["reported"])
if err != nil {
return err
}
return nil
}
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"result": o.Result,
}
}
func (o *Output) FromMap(values map[string]interface{}) error {
var err error
o.Result, err = coerce.ToObject(values["result"])
if err != nil {
return err
}
return nil
}