summaryrefslogtreecommitdiff
path: root/internal/title/href.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2019-07-06 20:06:11 +0200
committerDimitri Sokolyuk <demon@dim13.org>2019-07-06 20:06:11 +0200
commita0c782f83d7349cb5abda92647545e9a78b41502 (patch)
tree4a73a0bc3c3ecdfdb708693452861c376309c370 /internal/title/href.go
parent5d55bc03e829afdad427f7539c1e08e65b88d409 (diff)
autoban
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)
}
}