Skip to content

Instantly share code, notes, and snippets.

@EtienneR
Created August 16, 2015 22:20
Show Gist options
  • Save EtienneR/0d8a678d5292997e4db1 to your computer and use it in GitHub Desktop.
Save EtienneR/0d8a678d5292997e4db1 to your computer and use it in GitHub Desktop.
RSS feed part2
package main
import (
"encoding/xml"
"fmt"
"os"
)
func main() {
type Item struct {
Title string `xml:"title"`
Link string `xml:"link"`
Description string `xml:"description"`
}
type rss struct {
Version string `xml:"version,attr"`
Description string `xml:"channel>description"`
Link string `xml:"channel>link"`
Title string `xml:"channel>title"`
Item Item `xml:"channel>item"`
}
articles := Item{"foo", "http://mywebsite.com/foo", "lorem ipsum"}
feed := &rss{
Version: "2.0",
Description: "My super website",
Link: "http://mywebsite.com",
Title: "Mywebsite",
Item: articles,
}
enc := xml.NewEncoder(os.Stdout)
enc.Indent(" ", " ")
if err := enc.Encode(feed); err != nil {
fmt.Printf("error: %feed\n", err)
}
}
<rss version="2.0">
<channel>
<description>My super website</description>
<link>http://mywebsite.com</link>
<title>Mywebsite</title>
<item>
<title>foo</title>
<link>http://mywebsite.com/foo</link>
<description>lorem ipsum</description>
</item>
</channel>
</rss>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment