forked from raviqqe/muffet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.go
47 lines (35 loc) · 847 Bytes
/
result.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
package main
import (
"sort"
"strings"
"github.com/fatih/color"
)
type result struct {
url string
successMessages, errorMessages []string
}
func newResult(u string, ss, es []string) result {
return result{u, ss, es}
}
func (r result) OK() bool {
return len(r.errorMessages) == 0
}
func (r result) String(v bool) string {
ss := []string(nil)
if v {
ss = formatMessages(color.GreenString("OK"), r.successMessages)
}
return strings.Join(
append(append([]string{color.YellowString(r.url)},
ss...),
formatMessages(color.RedString("ERROR"), r.errorMessages)...),
"\n")
}
func formatMessages(prefix string, ss []string) []string {
ts := make([]string, 0, len(ss))
for _, s := range ss {
ts = append(ts, strings.Join([]string{"\t", prefix, "\t", s}, ""))
}
sort.Strings(ts)
return ts
}