-
Notifications
You must be signed in to change notification settings - Fork 0
/
report.go
70 lines (60 loc) · 1.51 KB
/
report.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
63
64
65
66
67
68
69
70
package report
import (
"github.com/olekukonko/tablewriter"
"os"
"strings"
)
type Report interface {
FormatDataToTable() [][]string
GetHeaders() []string
}
func PrintTable(r Report) {
data := r.FormatDataToTable()
table := tablewriter.NewWriter(os.Stdout)
// Configure Headers
table.SetReflowDuringAutoWrap(false)
table.SetAutoFormatHeaders(false)
table.SetHeader(customFormatHeaders(r.GetHeaders()))
// Configure rows&cells
table.SetRowSeparator("-")
table.SetRowLine(true)
table.SetAutoWrapText(false)
table.AppendBulk(data)
table.Render()
}
func customFormatHeaders(headers []string) []string {
for i, header := range headers {
headers[i] = Title(header)
}
return headers
}
func Title(name string) string {
origLen := len(name)
name = strings.Replace(name, "_", " ", -1)
//name = strings.Replace(name, ".", " ", -1)
name = strings.TrimSpace(name)
if len(name) == 0 && origLen > 0 {
// Keep at least one character. This is important to preserve
// empty lines in multi-line headers/footers.
name = " "
}
return strings.ToUpper(name)
}
type EncryptionType int
const (
// NONE : No Encryption
NONE EncryptionType = 0
// AES256 : 256-bit Advanced Encryption Standard
AES256 EncryptionType = 1
// DKMS : Encrypted with default KMS Key
DKMS EncryptionType = 2
// CKMS : Encrypted with Custom KMS Key
CKMS EncryptionType = 3
)
func (et EncryptionType) String() string {
types := [...]string{"NONE", "AES256", "DKMS", "CKMS"}
if et < NONE || et > CKMS {
return "Unknown"
}
return types[et]
}