diff options
| author | demo <demo@antix1> | 2026-05-09 09:58:00 -0400 |
|---|---|---|
| committer | demo <demo@antix1> | 2026-05-09 09:58:00 -0400 |
| commit | 7fe62a3f676d810c8df46fa24a7314a2209a9dd2 (patch) | |
| tree | 47986644bfe3dcd58ceab737c91c6778e600264f | |
| parent | 29d93b1089c591b0d9de60f983e5528caa42b7f6 (diff) | |
feat: use better formatting when printing found links
| -rw-r--r-- | cmd/httpclient/main.go | 4 | ||||
| -rw-r--r-- | cmd/localclient/main.go | 4 | ||||
| -rw-r--r-- | internal/findlinks/findlinks.go | 8 |
3 files changed, 14 insertions, 2 deletions
diff --git a/cmd/httpclient/main.go b/cmd/httpclient/main.go index 945ee36..3744d78 100644 --- a/cmd/httpclient/main.go +++ b/cmd/httpclient/main.go @@ -46,5 +46,7 @@ func main() { log.Fatal(err) } - fmt.Println(links) + for _, link := range links { + fmt.Printf("%s\n\n", findlinks.Format(link, "\n")) + } } diff --git a/cmd/localclient/main.go b/cmd/localclient/main.go index 578a786..d0b7e41 100644 --- a/cmd/localclient/main.go +++ b/cmd/localclient/main.go @@ -41,5 +41,7 @@ func main() { log.Fatal(err) } - fmt.Printf("%+v\n", links) + for _, link := range links { + fmt.Printf("%s\n\n", findlinks.Format(link, "\n")) + } } diff --git a/internal/findlinks/findlinks.go b/internal/findlinks/findlinks.go index a281a49..ad2e30c 100644 --- a/internal/findlinks/findlinks.go +++ b/internal/findlinks/findlinks.go @@ -15,6 +15,14 @@ type Link struct { Text string } +// Format returns a suitable string representation of a link. +// +// Argument sep (e.g. " ", "\n") customizes how the href should be +// displayed alongside the text. +func Format(link Link, sep string) string { + return fmt.Sprintf("%s%s%s", link.Text, sep, link.Href) +} + // FindLinks consumes the given [io.Reader], scraping it of anchor // tags. Each anchor tag is "unmarshalled" into a [Link]. The // resulting slice of Links is returned, along with an error. |
