refactor: log parsers naming mostly

This commit is contained in:
Inanc Gumus
2019-04-26 01:20:41 +03:00
parent 7202f21c13
commit be36a2246d
2 changed files with 17 additions and 17 deletions

View File

@ -45,16 +45,16 @@ func main() {
return return
} }
name := fields[0] domain := fields[0]
// Collect the unique domains // Collect the unique domains
if _, ok := sum[name]; !ok { if _, ok := sum[domain]; !ok {
domains = append(domains, name) domains = append(domains, domain)
} }
// Keep track of total and per domain visits // Keep track of total and per domain visits
total += visits total += visits
sum[name] += visits sum[domain] += visits
} }
// Print the visits per domain // Print the visits per domain
@ -63,9 +63,9 @@ func main() {
fmt.Printf("%-30s %10s\n", "DOMAIN", "VISITS") fmt.Printf("%-30s %10s\n", "DOMAIN", "VISITS")
fmt.Println(strings.Repeat("-", 45)) fmt.Println(strings.Repeat("-", 45))
for _, name := range domains { for _, domain := range domains {
visits := sum[name] visits := sum[domain]
fmt.Printf("%-30s %10d\n", name, visits) fmt.Printf("%-30s %10d\n", domain, visits)
} }
// Print the total visits for all domains // Print the total visits for all domains

View File

@ -19,7 +19,7 @@ import (
// visit stores metrics for a domain // visit stores metrics for a domain
type visit struct { type visit struct {
domain string domain string
count int total int
// add more metrics if needed // add more metrics if needed
} }
@ -53,11 +53,11 @@ func main() {
return return
} }
name := fields[0] domain := fields[0]
// Collect the unique domains // Collect the unique domains
if _, ok := p.sum[name]; !ok { if _, ok := p.sum[domain]; !ok {
p.domains = append(p.domains, name) p.domains = append(p.domains, domain)
} }
// Keep track of total and per domain visits // Keep track of total and per domain visits
@ -67,9 +67,9 @@ func main() {
// p.sum[name].count += visits // p.sum[name].count += visits
// create and assign a new copy of `visit` // create and assign a new copy of `visit`
p.sum[name] = visit{ p.sum[domain] = visit{
domain: name, domain: domain,
count: visits + p.sum[name].count, total: visits + p.sum[domain].total,
} }
} }
@ -79,9 +79,9 @@ func main() {
fmt.Printf("%-30s %10s\n", "DOMAIN", "VISITS") fmt.Printf("%-30s %10s\n", "DOMAIN", "VISITS")
fmt.Println(strings.Repeat("-", 45)) fmt.Println(strings.Repeat("-", 45))
for _, name := range p.domains { for _, domain := range p.domains {
visits := p.sum[name] visits := p.sum[domain]
fmt.Printf("%-30s %10d\n", name, visits.count) fmt.Printf("%-30s %10d\n", domain, visits.total)
} }
// Print the total visits for all domains // Print the total visits for all domains