-
Notifications
You must be signed in to change notification settings - Fork 20
/
regular.go
54 lines (47 loc) · 1.4 KB
/
regular.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package rss
import (
"encoding/xml"
"net/http"
"github.com/paulrosania/go-charset/charset"
)
//Channel struct for RSS
type Channel struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
Language string `xml:"language"`
LastBuildDate Date `xml:"lastBuildDate"`
Item []Item `xml:"item"`
}
//ItemEnclosure struct for each Item Enclosure
type ItemEnclosure struct {
URL string `xml:"url,attr"`
Type string `xml:"type,attr"`
}
//Item struct for each Item in the Channel
type Item struct {
Title string `xml:"title"`
Link string `xml:"link"`
Comments string `xml:"comments"`
PubDate Date `xml:"pubDate"`
GUID string `xml:"guid"`
Category []string `xml:"category"`
Enclosure []ItemEnclosure `xml:"enclosure"`
Description string `xml:"description"`
Author string `xml:"author"`
Content string `xml:"content"`
FullText string `xml:"full-text"`
}
//Regular parses regular feeds
func Regular(resp *http.Response) (*Channel, error) {
defer resp.Body.Close()
xmlDecoder := xml.NewDecoder(resp.Body)
xmlDecoder.CharsetReader = charset.NewReader
var rss struct {
Channel Channel `xml:"channel"`
}
if err := xmlDecoder.Decode(&rss); err != nil {
return nil, err
}
return &rss.Channel, nil
}