generated from templates/go-generic
refactor: replace internal with linkType in record struct
This commit is contained in:
parent
e4650bf62e
commit
e2cb65dc03
1 changed files with 9 additions and 12 deletions
|
@ -17,25 +17,22 @@ type report struct {
|
||||||
type record struct {
|
type record struct {
|
||||||
link string
|
link string
|
||||||
count int
|
count int
|
||||||
internal bool
|
linkType string
|
||||||
}
|
|
||||||
|
|
||||||
func (r record) linkType() string {
|
|
||||||
if r.internal {
|
|
||||||
return "internal"
|
|
||||||
}
|
|
||||||
|
|
||||||
return "external"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func newReport(format, baseURL string, pages map[string]pageStat) report {
|
func newReport(format, baseURL string, pages map[string]pageStat) report {
|
||||||
records := make([]record, 0)
|
records := make([]record, 0)
|
||||||
|
|
||||||
for link, stats := range maps.All(pages) {
|
for link, stats := range maps.All(pages) {
|
||||||
|
linkType := "internal"
|
||||||
|
if !stats.internal {
|
||||||
|
linkType = "external"
|
||||||
|
}
|
||||||
|
|
||||||
record := record{
|
record := record{
|
||||||
link: link,
|
link: link,
|
||||||
count: stats.count,
|
count: stats.count,
|
||||||
internal: stats.internal,
|
linkType: linkType,
|
||||||
}
|
}
|
||||||
|
|
||||||
records = append(records, record)
|
records = append(records, record)
|
||||||
|
@ -88,7 +85,7 @@ func (r report) text() string {
|
||||||
links = "link"
|
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()
|
return builder.String()
|
||||||
|
@ -100,7 +97,7 @@ func (r report) csv() string {
|
||||||
builder.WriteString("LINK,TYPE,COUNT")
|
builder.WriteString("LINK,TYPE,COUNT")
|
||||||
|
|
||||||
for ind := range slices.All(r.records) {
|
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()
|
return builder.String()
|
||||||
|
|
Loading…
Reference in a new issue