Created
August 16, 2015 22:24
-
-
Save EtienneR/c93da1b9682af9e31f30 to your computer and use it in GitHub Desktop.
RSS feed part3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"}, | |
{"foo2", "http://mywebsite.com/foo2", "lorem ipsum2"}} | |
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) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
<item> | |
<title>foo2</title> | |
<link>http://mywebsite.com/foo2</link> | |
<description>lorem ipsum2</description> | |
</item> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment