Skip to content

Instantly share code, notes, and snippets.

@losinggeneration
Created September 25, 2012 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save losinggeneration/3782515 to your computer and use it in GitHub Desktop.
Save losinggeneration/3782515 to your computer and use it in GitHub Desktop.
Possible Go RSS formatter
package rss
import "encoding/xml"
type Channel struct {
XMLName xml.Name `xml:"channel"`
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"url"`
LastBuildDate string `xml:"lastBuildDate"`
PubDate string `xml:"pubDate"`
TTL int `xml:"ttl"`
Items []Item
}
type Item struct {
XMLName xml.Name `xml:"item"`
Title string `xml:"title"`
Description string `xml:"description"`
Link string `xml:"url"`
GUID string `xml:"guid"`
PubDate string `xml:"pubDate"`
}
type RSS struct {
XMLName xml.Name `xml:"rss"`
Version float64 `xml:"version,attr"`
Channel Channel
}
func BuildRSS(r *RSS) ([]byte, error) {
return xml.Marshal(r)
}
package rss
import (
"testing"
"time"
"code.google.com/p/tcgl/identifier"
)
func TestEmpty(t *testing.T) {
if _, e := BuildRSS(&RSS{}); e != nil {
t.Error(e)
}
}
func TestRSS(t *testing.T) {
var rss = &RSS{
Version: 2.0,
Channel: Channel{
Title: "Test RSS",
Description: "This is an example RSS",
Link: "http://www.some-syndication.com/",
LastBuildDate: time.Now().Format(time.RFC1123Z),
PubDate :time.Now().Format(time.RFC1123Z),
TTL: 1800,
Items: []Item{
{
Title: "Some great information here",
Description: "This was a second example post",
Link:"http://www.some-syndication.com/post2",
GUID: identifier.NewUUID().String(),
PubDate:time.Now().Format(time.RFC1123Z),
}, {
Title: "Hello, World!",
Description: "This was the first post, hello world!",
Link:"http://www.some-syndication.com/post1",
GUID: identifier.NewUUID().String(),
PubDate:time.Now().Format(time.RFC1123Z),
},
},
},
}
if _, e := BuildRSS(rss); e != nil {
t.Error(e)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment