summaryrefslogtreecommitdiff
path: root/internal/title/href.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/title/href.go')
-rw-r--r--internal/title/href.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/internal/title/href.go b/internal/title/href.go
index cae1a18..2b6b89f 100644
--- a/internal/title/href.go
+++ b/internal/title/href.go
@@ -35,19 +35,29 @@ func New(w io.Writer) *Titles {
return &Titles{cache: cache, w: w}
}
-func (t *Titles) Parse(text string) {
+func (t Titles) get(url string) (string, bool) {
+ if title, ok := t.cache.Get(url); ok {
+ return title.(string), true
+ }
+ return "", false
+}
+
+func (t Titles) set(url, title string) {
+ t.cache.Add(url, title)
+}
+
+func (t Titles) Parse(text string) {
for _, v := range parseLinks(text) {
if v == "" {
continue
}
- title, ok := t.cache.Get(v)
- if ok {
+ if title, ok := t.get(v); ok {
fmt.Fprintf(t.w, "Title: %v (cached)", title)
continue
}
title, err := fetch(v)
if err == nil {
- t.cache.Add(v, title)
+ t.set(v, title)
fmt.Fprintf(t.w, "Title: %v", title)
}
}