/
healthprinter.go
87 lines (71 loc) · 1.67 KB
/
healthprinter.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package output
import (
"sort"
"github.com/fi-ts/cloud-go/api/models"
)
type (
// HealthTablePrinter
HealthTablePrinter struct {
tablePrinter
}
)
func (p HealthTablePrinter) Print(health *models.RestHealthResponse) {
p.wideHeader = []string{"Overall Status", "Message"}
p.shortHeader = p.wideHeader
status := "unknown"
if health.Status != nil && *health.Status != "" {
status = *health.Status
}
msg := ""
if health.Message != nil && *health.Message != "" {
msg = *health.Message
}
wide := []string{status, msg}
p.addWideData(wide, health)
p.addShortData(wide, health)
p.render()
}
func (p HealthTablePrinter) PrintServices(services map[string]models.RestHealthResult) {
p.wideHeader = []string{"Service", "Status", "Message"}
p.shortHeader = p.wideHeader
keys := make([]string, 0, len(services))
for k := range services {
keys = append(keys, k)
}
sort.Strings(keys)
for _, name := range keys {
s := services[name]
status := "unknown"
if s.Status != nil && *s.Status != "" {
status = *s.Status
}
msg := ""
if s.Message != nil && *s.Message != "" {
msg = *s.Message
}
wide := []string{name, status, msg}
p.addWideData(wide, s)
p.addShortData(wide, s)
i := 0
for sname, sresult := range s.Services {
prefix := "├"
if i == len(s.Services)-1 {
prefix = "└"
}
prefix += "─╴"
status := "unknown"
if sresult.Status != nil && *sresult.Status != "" {
status = *sresult.Status
}
msg := ""
if sresult.Message != nil && *sresult.Message != "" {
msg = *s.Message
}
wide := []string{prefix + sname, status, msg}
p.addWideData(wide, s)
p.addShortData(wide, s)
i++
}
}
p.render()
}