-
Notifications
You must be signed in to change notification settings - Fork 13
/
metadata.go
73 lines (61 loc) · 2.16 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
63
64
65
66
67
68
69
70
71
72
73
package mqtt
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
Broker string `md:"broker,required"` // The broker URL
Id string `md:"id,required"` // The id of client
Username string `md:"username"` // The user's name
Password string `md:"password"` // The user's password
Store string `md:"store"` // The store for message persistence
CleanSession bool `md:"cleanSession"` // Clean session flag
KeepAlive int `md:"keepAlive"` // Keep Alive time in seconds
AutoReconnect bool `md:"autoReconnect"` // Enable Auto-Reconnect
SSLConfig map[string]interface{} `md:"sslConfig"` // SSL Configuration
}
type HandlerSettings struct {
Topic string `md:"topic,required"` // The topic to listen on
ReplyTopic string `md:"replyTopic"` // The topic to reply on
Qos int `md:"qos"` // The Quality of Service
Retain bool `md:"retain"` // Retain messages
}
type Output struct {
Message string `md:"message"` // The message recieved
Topic string `md:"topic"` // The MQTT topic
TopicParams map[string]string `md:"topicParams"` // The topic parameters
}
type Reply struct {
Data interface{} `md:"data"` // The data to reply with
}
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"message": o.Message,
"topic": o.Topic,
"topicParams": o.TopicParams,
}
}
func (o *Output) FromMap(values map[string]interface{}) error {
var err error
o.Message, err = coerce.ToString(values["message"])
if err != nil {
return err
}
o.Topic, err = coerce.ToString(values["topic"])
if err != nil {
return err
}
o.TopicParams, err = coerce.ToParams(values["topicParams"])
if err != nil {
return err
}
return nil
}
func (r *Reply) ToMap() map[string]interface{} {
return map[string]interface{}{
"data": r.Data,
}
}
func (r *Reply) FromMap(values map[string]interface{}) error {
r.Data = values["data"]
return nil
}