-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.go
55 lines (47 loc) · 1.33 KB
/
rss.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
55
package main
import "encoding/xml"
// https://validator.w3.org/feed/docs/rss2.html
type RSS struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
Channel RSSChannel `xml:"channel"`
}
type RSSChannel struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
LastBuildDate string `xml:"lastBuildDate"`
Items []RSSItem `xml:"item"`
}
type RSSItem struct {
Title string `xml:"title"`
Link string `xml:"link"`
PublishDate string `xml:"pubDate"`
GUID string `xml:"guid"`
Description CDATA `xml:"description"`
}
type CDATA struct {
Value string `xml:",cdata"`
}
func NewRSS(response *InshortsNewsResponse, title string) *RSS {
rss := RSS{
Version: "2.0",
Channel: RSSChannel{
Title: title,
Link: "https://www.inshorts.com/",
Description: "Inshorts RSS Feed",
LastBuildDate: response.GetLastNewsDate(),
},
}
for _, item := range response.Data.NewsList {
rssItem := RSSItem{
Title: item.NewsObject.Title,
Link: item.NewsObject.URL,
Description: CDATA{item.NewsObject.GetMarkupContent()},
PublishDate: item.NewsObject.GetCreatedAt(),
GUID: item.NewsObject.URL,
}
rss.Channel.Items = append(rss.Channel.Items, rssItem)
}
return &rss
}