...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package collector
17
18 import (
19 "encoding/json"
20
21 "github.com/chaos-mesh/chaos-mesh/api/v1alpha1"
22 )
23
24 type ValuedCollector struct {
25 status v1alpha1.ConditionalBranchesStatus
26 }
27
28 func NewValuedCollector(status v1alpha1.ConditionalBranchesStatus) *ValuedCollector {
29 return &ValuedCollector{status: status}
30 }
31
32 func (it *ValuedCollector) CollectContext() (env map[string]interface{}, err error) {
33 if len(it.status.Context) == 0 {
34 return nil, nil
35 }
36 result := make(map[string]interface{})
37 for _, jsonString := range it.status.Context {
38 var tmp map[string]interface{}
39 err := json.Unmarshal([]byte(jsonString), &tmp)
40 if err != nil {
41 return nil, err
42 }
43 mapExtend(result, tmp)
44 }
45 return result, err
46 }
47