-
Notifications
You must be signed in to change notification settings - Fork 4
/
15-go-pretty-another-styles.go
60 lines (49 loc) · 1.37 KB
/
15-go-pretty-another-styles.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
// Seriál "Programovací jazyk Go"
// https://www.root.cz/serialy/programovaci-jazyk-go/
//
// Sedmdesátá první část
// Formátovaný tisk obsahu tabulek a dalších datových struktur v Go
// https://www.root.cz/clanky/formatovany-tisk-obsahu-tabulek-a-dalsich-datovych-struktur-v-go/
//
// Repositář:
// https://github.com/tisnik/go-root/
//
// Seznam příkladů ze sedmdesáté první části:
// https://github.com/tisnik/go-root/blob/master/article_71/README.md
package main
import (
"os"
"github.com/jedib0t/go-pretty/table"
)
// Role represents user role in some IS
type Role struct {
name string
surname string
popularity int
}
func main() {
roles := []Role{
{"Eliška", "Najbrtová", 4},
{"Jenny", "Suk", 3},
{"Anička", "Šafářová", 1},
{"Sváťa", "Pulec", 3},
{"Blažej", "Motyčka", 8},
{"Eda", "Wasserfall", 3},
{"Přemysl", "Hájek", 10},
}
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"#", "First Name", "Last Name", "Popularity"})
totalPopularity := 0
for i, role := range roles {
t.AppendRow(table.Row{i, role.name, role.surname, role.popularity})
totalPopularity += role.popularity
}
t.AppendFooter(table.Row{"", "", "Total", totalPopularity})
t.SetStyle(table.StyleBold)
t.Render()
t.SetStyle(table.StyleDouble)
t.Render()
t.SetStyle(table.StyleRounded)
t.Render()
}