-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmetadata.go
61 lines (49 loc) · 1.76 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
package mongodb
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
URI string `md:"uri,required"` // The MongoDB connection URI
Method string `md:"method,required,allowed(GET,INSERT,UPDATE,DELETE)"` // The method type
DbName string `md:"dbName,required"` // The name of the database
Collection string `md:"collection, required"` // The collection to work on
Username string `md:"username"` // The username of the client
Password string `md:"password"` // The password of the client
}
type Input struct {
KeyName string `md:"keyName"` // The name of the key to use when looking up an object (used in GET, UPDATE and DELETE)
KeyValue string `md:"keyValue"` // The value of the key to use when looking up an object (used in GET, UPDATE, and DELETE)
Data interface{} `md:"data"` // The bson document to insert in mongodb
}
func (i *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"keyName": i.KeyName,
"keyValue": i.KeyValue,
"data": i.Data,
}
}
func (i *Input) FromMap(values map[string]interface{}) error {
var err error
i.KeyName, err = coerce.ToString(values["keyName"])
if err != nil {
return err
}
i.KeyValue, err = coerce.ToString(values["keyValue"])
if err != nil {
return err
}
i.Data, _ = values["data"]
return nil
}
type Output struct {
Data interface{} `md:"data"`
}
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"data": o.Data,
}
}
func (o *Output) FromMap(values map[string]interface{}) error {
o.Data, _ = values["data"]
return nil
}