refactor: methods log parser

This commit is contained in:
Inanc Gumus
2019-05-10 14:42:37 +03:00
parent d979da2d44
commit 500f264d8b

View File

@ -44,21 +44,21 @@ func encode(sum *report.Summary) {
// prints the summary to standard out // prints the summary to standard out
func stdout(sum *report.Summary) { func stdout(sum *report.Summary) {
const format = "%-30s %10s %20s\n" const (
const formatValue = "%-30s %10d %20d\n" head = "%-30s %10s %20s\n"
val = "%-30s %10d %20d\n"
)
fmt.Printf(format, "DOMAIN", "VISITS", "TIME SPENT") fmt.Printf(head, "DOMAIN", "VISITS", "TIME SPENT")
fmt.Println(strings.Repeat("-", 65)) fmt.Println(strings.Repeat("-", 65))
next, cur := sum.Iterator() for next, cur := sum.Iterator(); next(); {
for next() { r := cur()
rec := cur() fmt.Printf(val, r.Domain, r.Visits, r.TimeSpent)
fmt.Printf(formatValue, rec.Domain, rec.Visits, rec.TimeSpent)
} }
fmt.Printf("\n"+formatValue, "TOTAL", t := sum.Total()
sum.Total().Visits, sum.Total().TimeSpent, fmt.Printf("\n"+val, "TOTAL", t.Visits, t.TimeSpent)
)
} }
// this variadic func simplifies the multiple error handling // this variadic func simplifies the multiple error handling