From cbd28126ea8cabfd1b422ce30c83bd763096dd50 Mon Sep 17 00:00:00 2001 From: Inanc Gumus Date: Wed, 24 Apr 2019 22:33:45 +0300 Subject: [PATCH] fix: log parser for structs --- .../log.txt | 0 .../main.go | 8 ++++---- 2 files changed, 4 insertions(+), 4 deletions(-) rename {25-project-file-parser-structs => 25-project-log-parser-structs}/log.txt (100%) rename {25-project-file-parser-structs => 25-project-log-parser-structs}/main.go (93%) diff --git a/25-project-file-parser-structs/log.txt b/25-project-log-parser-structs/log.txt similarity index 100% rename from 25-project-file-parser-structs/log.txt rename to 25-project-log-parser-structs/log.txt diff --git a/25-project-file-parser-structs/main.go b/25-project-log-parser-structs/main.go similarity index 93% rename from 25-project-file-parser-structs/main.go rename to 25-project-log-parser-structs/main.go index 09314d8..2ad43ba 100644 --- a/25-project-file-parser-structs/main.go +++ b/25-project-log-parser-structs/main.go @@ -51,8 +51,8 @@ func main() { name, visits := fields[0], fields[1] // Sum the total visits per domain - n, _ := strconv.Atoi(visits) - if n < 0 { + n, err := strconv.Atoi(visits) + if n < 0 || err != nil { fmt.Printf("wrong input: %q (line #%d)\n", visits, p.lines) return } @@ -60,11 +60,11 @@ func main() { d := domain{name: name, visits: n} // Collect the unique domains - if _, ok := p.sum[name]; !ok { + if _, ok := p.sum[d.name]; !ok { p.domains = append(p.domains, d) } - p.sum[d.name] += n + p.sum[d.name] += d.visits p.total += d.visits }