Created
August 16, 2015 22:20
-
-
Save EtienneR/0d8a678d5292997e4db1 to your computer and use it in GitHub Desktop.
RSS feed part2
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"} | |
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> | |
</channel> | |
</rss> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment