From e2cb65dc035e7e245049f4abc69279d0517c5ba2 Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Wed, 28 Aug 2024 14:51:34 +0100 Subject: [PATCH] refactor: replace internal with linkType in record struct --- internal/crawler/report.go | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/internal/crawler/report.go b/internal/crawler/report.go index 88a5a44..c6e947d 100644 --- a/internal/crawler/report.go +++ b/internal/crawler/report.go @@ -17,25 +17,22 @@ type report struct { type record struct { link string count int - internal bool -} - -func (r record) linkType() string { - if r.internal { - return "internal" - } - - return "external" + linkType string } func newReport(format, baseURL string, pages map[string]pageStat) report { records := make([]record, 0) for link, stats := range maps.All(pages) { + linkType := "internal" + if !stats.internal { + linkType = "external" + } + record := record{ link: link, count: stats.count, - internal: stats.internal, + linkType: linkType, } records = append(records, record) @@ -88,7 +85,7 @@ func (r report) text() string { links = "link" } - builder.WriteString("\nFound " + strconv.Itoa(r.records[ind].count) + " " + r.records[ind].linkType() + " " + links + " to " + r.records[ind].link) + builder.WriteString("\nFound " + strconv.Itoa(r.records[ind].count) + " " + r.records[ind].linkType + " " + links + " to " + r.records[ind].link) } return builder.String() @@ -100,7 +97,7 @@ func (r report) csv() string { builder.WriteString("LINK,TYPE,COUNT") for ind := range slices.All(r.records) { - builder.WriteString("\n" + r.records[ind].link + "," + r.records[ind].linkType() + "," + strconv.Itoa(r.records[ind].count)) + builder.WriteString("\n" + r.records[ind].link + "," + r.records[ind].linkType + "," + strconv.Itoa(r.records[ind].count)) } return builder.String()