-
Notifications
You must be signed in to change notification settings - Fork 13
/
metadata.go
62 lines (51 loc) · 1.56 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 coap
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
Method string `md:"method,required"` // The CoAP method to use
URI string `md:"uri,required"` // The CoAP resource URI
MessageType string `md:"messageType"` // The message type
Options map[string]string `md:"options"` // The CoAP options to set
}
type Input struct {
QueryParams map[string]string `md:"queryParams"` // The query params of the CoAP message
MessageId int `md:"messageId"` // ID used to detect duplicates and for optional reliability
Payload string `md:"payload"` // The payload of the CoAP message
}
type Output struct {
Response string `md:"response"` // The response
}
func (i *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"queryParams": i.QueryParams,
"payload": i.Payload,
"messageId": i.MessageId,
}
}
func (i *Input) FromMap(values map[string]interface{}) error {
var err error
i.QueryParams, err = coerce.ToParams(values["queryParams"])
if err != nil {
return err
}
i.Payload, err = coerce.ToString(values["payload"])
if err != nil {
return err
}
i.MessageId, err = coerce.ToInt(values["messageId"])
return err
}
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"response": o.Response,
}
}
func (o *Output) FromMap(values map[string]interface{}) error {
var err error
o.Response, err = coerce.ToString(values["response"])
if err != nil {
return err
}
return nil
}