1
|
package main
|
2
|
|
3
|
import (
|
4
|
"encoding/json"
|
5
|
"fmt"
|
6
|
"time"
|
7
|
)
|
8
|
|
9
|
type ruleOp_t int
|
10
|
|
11
|
const (
|
12
|
ruleOpEQ ruleOp_t = iota // Equal to
|
13
|
ruleOpNE // Not equal to
|
14
|
ruleOpGT // Greater than
|
15
|
ruleOpGE // Greater than or equal to
|
16
|
ruleOpLT // Less than
|
17
|
ruleOpLE // Less than or equal to
|
18
|
)
|
19
|
|
20
|
type ActionSet_t struct {
|
21
|
Tasks []string `json:"tasks"`
|
22
|
Properties map[string]string `json:"properties"`
|
23
|
}
|
24
|
|
25
|
type TraceDataRuleL2Pattern_t struct {
|
26
|
Attr string `json:"attr"`
|
27
|
EntityVal string `json:"entityval"`
|
28
|
Op ruleOp_t `json:"op"`
|
29
|
RuleVal string `json:"ruleval"`
|
30
|
Match bool `json:"match"`
|
31
|
}
|
32
|
|
33
|
type TraceDataRuleL2_t struct {
|
34
|
Pattern []TraceDataRuleL2Pattern_t `json:"pattern"`
|
35
|
Tasks []string `json:"tasks"`
|
36
|
Properties map[string]string `json:"properties"`
|
37
|
NextSet int `json:"nextset"`
|
38
|
ActionSet ActionSet_t `json:"actionset"`
|
39
|
}
|
40
|
|
41
|
type TraceDataRule_t struct {
|
42
|
RuleNo int `json:"r"`
|
43
|
Res string `json:"res"`
|
44
|
NextSet int `json:"nextset"`
|
45
|
L2Data TraceDataRuleL2_t `json:"l2data"`
|
46
|
}
|
47
|
|
48
|
type TraceData_t struct {
|
49
|
SetID int `json:"id"`
|
50
|
SetName string `json:"setName"`
|
51
|
Rules []TraceDataRule_t `json:"rules"`
|
52
|
}
|
53
|
|
54
|
type Trace_t struct {
|
55
|
Start time.Time `json:"start"`
|
56
|
End time.Time `json:"end"`
|
57
|
Realm string `json:"realm"`
|
58
|
App string `json:"app"`
|
59
|
EntryRulesetID int `json:"entryRulesetID"`
|
60
|
EntryRulesetName string `json:"entryRulesetName"`
|
61
|
TraceData []TraceData_t `json:"tracedata"`
|
62
|
}
|
63
|
|
64
|
func main() {
|
65
|
// Instantiate Trace_t with the provided sample data
|
66
|
trace := Trace_t{
|
67
|
Start: time.Now(),
|
68
|
End: time.Now(),
|
69
|
Realm: "ExampleRealm",
|
70
|
App: "ExampleApp",
|
71
|
TraceData: []TraceData_t{
|
72
|
{
|
73
|
SetID: 43,
|
74
|
SetName: "domesticremittance",
|
75
|
Rules: []TraceDataRule_t{
|
76
|
{
|
77
|
RuleNo: 0,
|
78
|
Res: "+",
|
79
|
},
|
80
|
},
|
81
|
},
|
82
|
{
|
83
|
SetID: 43,
|
84
|
SetName: "domesticremittance",
|
85
|
Rules: []TraceDataRule_t{
|
86
|
{
|
87
|
RuleNo: 3,
|
88
|
Res: "+",
|
89
|
},
|
90
|
{
|
91
|
RuleNo: 4,
|
92
|
Res: "-",
|
93
|
NextSet: 0,
|
94
|
L2Data: TraceDataRuleL2_t{
|
95
|
Pattern: []TraceDataRuleL2Pattern_t{
|
96
|
{
|
97
|
Attr: "ExampleAttr",
|
98
|
EntityVal: "ExampleVal",
|
99
|
Op: ruleOpEQ,
|
100
|
RuleVal: "ExpectedVal",
|
101
|
Match: true,
|
102
|
},
|
103
|
},
|
104
|
Properties: map[string]string{
|
105
|
"microfinance": "true",
|
106
|
},
|
107
|
Tasks: nil,
|
108
|
NextSet: 0,
|
109
|
ActionSet: ActionSet_t{
|
110
|
Tasks: []string{"priorityprofile", "totempole", "smallsector"},
|
111
|
Properties: map[string]string{
|
112
|
"microfinance": "true",
|
113
|
},
|
114
|
},
|
115
|
},
|
116
|
},
|
117
|
},
|
118
|
},
|
119
|
},
|
120
|
}
|
121
|
|
122
|
// Marshal
|
123
|
traceJSON, err := json.MarshalIndent(trace, "", " ")
|
124
|
if err != nil {
|
125
|
fmt.Println("Error marshalling to JSON:", err)
|
126
|
return
|
127
|
}
|
128
|
|
129
|
fmt.Println(string(traceJSON))
|
130
|
}
|