-
Notifications
You must be signed in to change notification settings - Fork 0
/
printer.go
57 lines (50 loc) · 973 Bytes
/
printer.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
package main
import (
"fmt"
"io"
"os"
"time"
)
const (
tab = "\t"
newline = "\n"
separator = "------------------------\n"
)
type errWriter struct {
w io.Writer
err error
}
func (ew *errWriter) write(a ...interface{}) {
if ew.err != nil {
return
}
_, ew.err = fmt.Fprint(ew.w, a...)
}
func writeBalancingFlow(src, lb, dst string) error {
switch config.Global.Output {
case "dict":
ew := &errWriter{w: os.Stdout}
ew.write(
" TIMESTAMP: ", time.Now().Format(time.RFC3339), newline,
" SOURCE: ", src, newline,
"LOADBALANCER: ", lb, newline,
" DESTINATION: ", dst, newline,
separator,
)
if ew.err != nil {
return fmt.Errorf("failed to write out packet: %v", ew.err)
}
case "compact":
_, err := fmt.Fprintf(os.Stdout,
"%s: %s -> %s -> %s \n",
time.Now().Format(time.RFC3339),
src,
lb,
dst,
)
if err != nil {
return fmt.Errorf("failed to write out packet: %v", err)
}
}
return nil
}