-
Notifications
You must be signed in to change notification settings - Fork 23
/
metadata.go
50 lines (42 loc) · 989 Bytes
/
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
package circuitbreaker
import (
"github.com/project-flogo/core/data/coerce"
)
type Settings struct {
Mode string `md:"mode,allowed(a,b,c,d)"`
Threshold int `md:"threshold"`
Period int `md:"period"`
Timeout int `md:"timeout"`
}
type Input struct {
Operation string `md:"operation,allowed(counter,reset)"`
}
func (r *Input) FromMap(values map[string]interface{}) error {
operation, err := coerce.ToString(values["operation"])
if err != nil {
return err
}
r.Operation = operation
return nil
}
func (r *Input) ToMap() map[string]interface{} {
return map[string]interface{}{
"operation": r.Operation,
}
}
type Output struct {
Tripped bool `md:"tripped"`
}
func (o *Output) FromMap(values map[string]interface{}) error {
tripped, err := coerce.ToBool(values["tripped"])
if err != nil {
return err
}
o.Tripped = tripped
return nil
}
func (o *Output) ToMap() map[string]interface{} {
return map[string]interface{}{
"tripped": o.Tripped,
}
}