summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2018-01-01 15:27:48 +0100
committerDimitri Sokolyuk <demon@dim13.org>2018-01-01 15:27:48 +0100
commita0f9fb2747c9cbd4c1793ada0667d46301ffbcac (patch)
tree75c1f62e28abec10c3e9c28adb1932135a36603f
parent1d20a28df8583ee5b8381bb3e4b4a23eec478597 (diff)
...
-rw-r--r--href.go18
1 files changed, 10 insertions, 8 deletions
diff --git a/href.go b/href.go
index 4118f0f..2cd7677 100644
--- a/href.go
+++ b/href.go
@@ -10,23 +10,25 @@ import (
)
var (
- errNotHTML = errors.New("Not HTML")
- errTooBig = errors.New("Content too big")
+ errNotHTML = errors.New("not HTML")
+ errTooBig = errors.New("content too big")
+ errNotTitle = errors.New("no Title")
)
-func title(n *html.Node) (s string) {
+func title(n *html.Node) (string, error) {
+ var s string
if n.Type == html.ElementNode && n.Data == "title" {
for c := n.FirstChild; c != nil; c = c.NextSibling {
s += c.Data
}
- return strings.TrimSpace(s)
+ return strings.TrimSpace(s), nil
}
for c := n.FirstChild; c != nil; c = c.NextSibling {
- if t := title(c); t != "" {
- return t
+ if t, err := title(c); err == nil {
+ return t, nil
}
}
- return ""
+ return "", errNotTitle
}
func getTitle(uri string) (string, error) {
@@ -55,7 +57,7 @@ func getTitle(uri string) (string, error) {
return "", err
}
- return title(doc), nil
+ return title(doc)
}
func getLinks(s string) (ret []string) {