-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patheasygo.go
115 lines (93 loc) · 2.34 KB
/
easygo.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package easygo
import (
"fmt"
"time"
"gopkg.pigeonligh.com/easygo/collections/counter"
"gopkg.pigeonligh.com/easygo/collections/meter"
log "gopkg.pigeonligh.com/easygo/elog"
"gopkg.pigeonligh.com/easygo/errors"
"gopkg.pigeonligh.com/easygo/pretty/list"
"gopkg.pigeonligh.com/easygo/pretty/table"
"gopkg.pigeonligh.com/easygo/pretty/text"
)
func logInit() {
log.Default() // or log.Debug()
}
func getError() error {
return errors.New("hello")
}
func testLog() {
l := log.With(map[string]string{
"fruit": "apple",
})
l.Info("Hello world")
}
func testErrors() {
var errs error
for i := 0; i < 5; i++ {
err := getError()
errs = errors.Merge(errs, err)
}
log.Info(errs)
}
func testMeter() {
m := meter.New()
n := meter.Make(1, 7, 4)
m.AddMeter(n)
m.Add(8)
m.Add(5)
log.Info(m.Sum(), m.Average(), m.Max(), m.Min())
log.Info(meter.Sum(1, 2, 3, 4, 5))
}
func testCounter() {
c := counter.New()
c.Pushes("apple", 5)
c.Pushes("banana", 3)
d := counter.New()
d.Pushes("apple", 2)
d.Pushes("banana", 5)
log.Info(c.Add(d))
log.Info(c.Sub(d))
log.Info(c.Max(d))
log.Info(c.Min(d))
}
func testList() {
l := list.New("Hello world")
l.Add("hello 1")
l.Get(-1).Add("world 1")
l.Get(-1).Get(-1).Add("!!!")
l.Get(-1).Add("world 2")
l.Get(-1).Get(-1).Add("!!!")
l.Add("hello 2")
l.Get(-1).Add("world 3")
l.Get(-1).Add("world 4")
fmt.Println(l.ToString(list.CircleRender))
// fmt.Println(l.ToString(list.HyphenReduceRender))
// fmt.Println(l.ToString(list.TreeRenderWithoutHeader))
// fmt.Println(l.ToString(list.NumberRender))
}
func testTable() {
t := table.NewByHeaders([]table.TableHeader{
{Text: "#", HeaderAlign: text.AlignCenter, TextAlign: text.AlignCenter},
{Text: "ask", HeaderAlign: text.AlignCenter, TextAlign: text.AlignLeft},
{Text: "answer", HeaderAlign: text.AlignCenter, TextAlign: text.AlignLeft},
})
t.AddRow(table.Row{1, "Hello, nice to meet you.", "Nice to meet you, too."})
t.AddRow(table.Row{2, "How are you?", "I'm fine, thank you."})
t.AddRow(table.Row{3, "What day is it today?", fmt.Sprintf("It's %s.", time.Now().Format("Monday"))})
fmt.Println(t.Render())
}
func testText() {
color := text.Colors{text.FontBold, text.FgGreen, text.BgBlue}
fmt.Println(color.Setup("hello world!"))
}
func Debugs() {
logInit()
testLog()
testErrors()
testMeter()
testCounter()
testList()
testTable()
testText()
}