-
Notifications
You must be signed in to change notification settings - Fork 0
/
rss.go
54 lines (44 loc) · 1006 Bytes
/
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
package main
import (
"encoding/xml"
"io"
"net/http"
"time"
)
type RssFeed struct {
Channel struct {
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"link"`
Language string `xml:"language"`
Items []RssItems `xml:"item"`
} `xml:"channel"`
}
type RssItems struct {
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"link"`
Creator string `xml:"dc:creator"`
PubDate string `xml:"pubDate"`
Cover_image string `xml:"cover_image"`
}
func getAllFeeds(url string) (RssFeed, error) {
httpClient := http.Client{
Timeout: 10 * time.Second,
}
res, err := httpClient.Get(url)
if err != nil {
return RssFeed{}, err
}
defer res.Body.Close()
data, err := io.ReadAll(res.Body)
if err != nil {
return RssFeed{}, err
}
storeData := RssFeed{}
err = xml.Unmarshal(data, &storeData)
if err != nil {
return RssFeed{}, err
}
return storeData, nil
}