summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/httpclient/main.go4
-rw-r--r--cmd/localclient/main.go4
-rw-r--r--internal/findlinks/findlinks.go8
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.