-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrss.go
35 lines (31 loc) · 889 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
package main
import (
"encoding/xml"
"fmt"
"io"
)
// Rss is the internal representation for a RSS feed
type Rss struct {
XMLName xml.Name `xml:"rss"`
Version string `xml:"version,attr"`
Title string `xml:"channel>title"`
Link string `xml:"channel>link"`
Description string `xml:"channel>description"`
Items []RssItem `xml:"channel>item"`
}
// RssItem is the internal representation for a RSS item
type RssItem struct {
Title string `xml:"title"`
Link string `xml:"link"`
Comments string `xml:"comments"`
Guid string `xml:"guid"`
Description string `xml:"description"`
}
// printXml serializes the RSS feed xml to an io.Writer
func (r *Rss) printXml(w io.Writer) error {
// Writes the xml of the rssfeed to w
fmt.Fprint(w, xml.Header)
enc := xml.NewEncoder(w)
enc.Indent("", " ")
return enc.Encode(r)
}