This repository was archived by the owner on Mar 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.go
More file actions
70 lines (58 loc) · 1.27 KB
/
data.go
File metadata and controls
70 lines (58 loc) · 1.27 KB
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
63
64
65
66
67
68
69
70
package log
import (
"bytes"
"fmt"
"github.com/olekukonko/tablewriter"
)
type LogRaw interface {
TableMarshal() ([]byte, error)
JsonMarshal() ([]byte, error)
}
type Fields map[string]interface{}
func (f Fields) TableMarshal() (bs []byte, err error) {
var header = make([]string, 0)
var data = [][]string{}
bf := bytes.NewBuffer(bs)
table := tablewriter.NewWriter(bf)
data_0 := []string{}
for k, v := range f {
header = append(header, k)
data_0 = append(data_0, fmt.Sprintf("%v", v))
}
data = append(data, data_0)
table.SetHeader(header)
table.SetAutoFormatHeaders(false)
for i := 0; i < len(data); i++ {
table.Append(data[i])
}
table.Render()
bs = bf.Bytes()
return
}
type Struct []KV
func (f Struct) TableMarshal() (bs []byte, err error) {
var header = make([]string, 0)
var data = [][]string{}
bf := bytes.NewBuffer(bs)
table := tablewriter.NewWriter(bf)
data_0 := []string{}
for i := 0; i < len(f); i++ {
k := f[i].K
v := f[i].V
header = append(header, k)
data_0 = append(data_0, fmt.Sprintf("%v", v))
}
data = append(data, data_0)
table.SetHeader(header)
table.SetAutoFormatHeaders(false)
for i := 0; i < len(data); i++ {
table.Append(data[i])
}
table.Render()
bs = bf.Bytes()
return
}
type KV struct {
K string
V interface{}
}