From 500f264d8b5128b2d4397fa1ce3552a1b6180798 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Fri, 10 May 2019 14:42:37 +0300 Subject: [PATCH] refactor: methods log parser --- 28-methods/xxx-log-parser/summarize.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/28-methods/xxx-log-parser/summarize.go b/28-methods/xxx-log-parser/summarize.go index dec3333..1d9b4ee 100644 --- a/28-methods/xxx-log-parser/summarize.go +++ b/28-methods/xxx-log-parser/summarize.go @@ -44,21 +44,21 @@ func encode(sum *report.Summary) { // prints the summary to standard out func stdout(sum *report.Summary) { - const format = "%-30s %10s %20s\n" - const formatValue = "%-30s %10d %20d\n" + const ( + 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)) - next, cur := sum.Iterator() - for next() { - rec := cur() - fmt.Printf(formatValue, rec.Domain, rec.Visits, rec.TimeSpent) + for next, cur := sum.Iterator(); next(); { + r := cur() + fmt.Printf(val, r.Domain, r.Visits, r.TimeSpent) } - fmt.Printf("\n"+formatValue, "TOTAL", - sum.Total().Visits, sum.Total().TimeSpent, - ) + t := sum.Total() + fmt.Printf("\n"+val, "TOTAL", t.Visits, t.TimeSpent) } // this variadic func simplifies the multiple error handling