forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
event.go
62 lines (54 loc) · 1.23 KB
/
event.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
package modetest
import (
"github.com/elastic/beats/libbeat/common"
"github.com/elastic/beats/libbeat/outputs"
)
type EventInfo struct {
Single bool
Data []outputs.Data
}
func SingleEvent(e common.MapStr) []EventInfo {
data := []outputs.Data{{Event: e}}
return []EventInfo{
{Single: true, Data: data},
}
}
func MultiEvent(n int, event common.MapStr) []EventInfo {
var data []outputs.Data
for i := 0; i < n; i++ {
data = append(data, outputs.Data{Event: event})
}
return []EventInfo{{Single: false, Data: data}}
}
func Repeat(n int, evt []EventInfo) []EventInfo {
var events []EventInfo
for _, e := range evt {
events = append(events, e)
}
return events
}
func EventsList(in []EventInfo) [][]outputs.Data {
var out [][]outputs.Data
for _, pubEvents := range in {
if pubEvents.Single {
for _, event := range pubEvents.Data {
out = append(out, []outputs.Data{event})
}
} else {
out = append(out, pubEvents.Data)
}
}
return out
}
func FlatEventsList(in []EventInfo) []outputs.Data {
return FlattenEvents(EventsList(in))
}
func FlattenEvents(data [][]outputs.Data) []outputs.Data {
var out []outputs.Data
for _, inner := range data {
for _, d := range inner {
out = append(out, d)
}
}
return out
}