-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathmetadata.go
62 lines (52 loc) · 1.23 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
59
60
61
62
package gpio
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
Method string `md:"method,required,allowed(Direction,Set State,Read State, Pull)"`
PinNumber int `md:"pinNumber,required"`
}
type Input struct {
Direction string `md:"direction,allowed(Input,Output)"`
State string `md:"state,allowed(High, Low)"`
Pull string `md:"pull,allowed(Up,Down,Off)"`
}
type Output struct {
Result int `md:"result"`
}
func (i *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"direction": i.Direction,
"state": i.State,
"pull": i.Pull,
}
}
func (i *Input) FromMap(values map[string]interface{}) error {
var err error
i.Direction, err = coerce.ToString(values["direction"])
if err != nil {
return err
}
i.State, err = coerce.ToString(values["state"])
if err != nil {
return err
}
i.Pull, err = coerce.ToString(values["pull"])
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.ToInt(values["direction"])
if err != nil {
return err
}
return nil
}