summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-20 16:06:07 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-20 16:06:07 +0200
commit1551a034bd1558694b436f324cddc1b5950097a5 (patch)
tree07395c8f2b74cf129f537fce559ff6e896577e8e
parentf5fb129c874481283781e477babd4106ed7a5775 (diff)
Add charset converter
-rw-r--r--href.go13
1 files changed, 10 insertions, 3 deletions
diff --git a/href.go b/href.go
index 2c4d915..3135840 100644
--- a/href.go
+++ b/href.go
@@ -6,11 +6,13 @@ import (
"strings"
"golang.org/x/net/html"
+ "golang.org/x/net/html/charset"
)
var (
- notHTML = errors.New("not HTML content")
- tooBig = errors.New("cotent too big")
+ notHTML = errors.New("not HTML content")
+ tooBig = errors.New("cotent too big")
+ iconvErr = errors.New("charset converter error")
)
const (
@@ -49,7 +51,12 @@ func FetchTitle(url string) (string, error) {
return "", tooBig
}
- doc, err := html.Parse(resp.Body)
+ r, err := charset.NewReader(resp.Body, ct)
+ if err != nil {
+ return "", iconvErr
+ }
+
+ doc, err := html.Parse(r)
if err != nil {
return "", err
}