summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-07-06 21:40:05 +0200
committerDimitri Sokolyuk <demon@dim13.org>2015-07-06 21:40:05 +0200
commit2f628f1139b6f55b4a401a59d5f6b84295af8785 (patch)
tree2691b356a15dbb90c71d85b195f53f1785441d9f
Initial import
-rw-r--r--rss.go43
1 files changed, 43 insertions, 0 deletions
diff --git a/rss.go b/rss.go
new file mode 100644
index 0000000..02388ef
--- /dev/null
+++ b/rss.go
@@ -0,0 +1,43 @@
+package rss
+
+import (
+ "encoding/xml"
+ "io/ioutil"
+ "net/http"
+)
+
+type RSS struct {
+ Version string `xml:"version,attr"`
+ Channel Channel `xml:"channel"`
+}
+
+type Channel struct {
+ Link string `xml:"link"`
+ Language string `xml:"language"`
+ Title string `xml:"title"`
+ Description string `xml:"description"`
+ PubDate string `xml:"pubDate"`
+ Items []Item `xml:"item"`
+}
+
+type Item struct {
+ Author string `xml:"author"`
+ Link string `xml:"link"`
+ GUID string `xml:"guid"`
+ Title string `xml:"title"`
+ PubDate string `xml:"pubDate"`
+}
+
+func Fetch(url string) (rss RSS, err error) {
+ resp, err := http.Get(url)
+ if err != nil {
+ return rss, err
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ err = xml.Unmarshal(body, &rss)
+ if err != nil {
+ return rss, err
+ }
+ return rss, nil
+}