walk events instead of printing directly

This commit is contained in:
Lorenzo Manacorda
2016-09-19 14:16:26 +02:00
parent 9e16db9490
commit f37b342a16
2 changed files with 16 additions and 4 deletions

View File

@@ -2,7 +2,6 @@ package endpoint
import (
"bufio"
"fmt"
"net"
"os"
"os/exec"
@@ -32,7 +31,8 @@ type ConnectionEvent struct {
}
type EbpfTracker struct {
Cmd *exec.Cmd
Cmd *exec.Cmd
Events []ConnectionEvent
}
func NewEbpfTracker(bccProgramPath string) *EbpfTracker {
@@ -135,6 +135,13 @@ func (t *EbpfTracker) run() {
DestPort: dPort,
}
fmt.Println(e)
t.Events = append(t.Events, e)
}
}
// WalkEvents - walk through the connectionEvents
func (t *EbpfTracker) WalkEvents(f func(ConnectionEvent)) {
for _, event := range t.Events {
f(event)
}
}

View File

@@ -16,7 +16,12 @@ func main() {
os.Exit(1)
}
time.Sleep(100 * time.Second)
// create some http connection within these 10 seconds
time.Sleep(10 * time.Second)
tr.WalkEvents(func(e endpoint.ConnectionEvent) {
fmt.Println(e)
})
fmt.Println("done")
}