diff --git a/atom.go b/atom.go index 3273d1a..d0eb33c 100644 --- a/atom.go +++ b/atom.go @@ -4,8 +4,8 @@ import ( "encoding/xml" "fmt" "net/url" - "time" "strconv" + "time" ) // Generates Atom feed as XML @@ -110,7 +110,6 @@ func newAtomEntry(i *Item) *AtomEntry { name, email = i.Author.Name, i.Author.Email } - x := &AtomEntry{ Title: i.Title, Link: &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type}, @@ -119,11 +118,12 @@ func newAtomEntry(i *Item) *AtomEntry { Updated: anyTimeFormat(time.RFC3339, i.Updated, i.Created), } - if(i.Link.Length>0) { - i.Link.Rel = "enclosure" - x.Link = &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type, Length: strconv.FormatInt(i.Link.Length,10)} - } + int_Length, err := strconv.ParseInt(i.Link.Length, 10, 64) + if err == nil && (int_Length > 0 || i.Link.Type != "") { + i.Link.Rel = "enclosure" + x.Link = &AtomLink{Href: i.Link.Href, Rel: i.Link.Rel, Type: i.Link.Type, Length: i.Link.Length} + } if len(name) > 0 || len(email) > 0 { x.Author = &AtomAuthor{AtomPerson: AtomPerson{Name: name, Email: email}} diff --git a/feed.go b/feed.go index bef34bd..fe4833e 100644 --- a/feed.go +++ b/feed.go @@ -7,8 +7,7 @@ import ( ) type Link struct { - Href, Rel,Type string - Length int64 + Href, Rel, Type, Length string } type Author struct { @@ -25,7 +24,6 @@ type Item struct { Created time.Time } - type Feed struct { Title string Link *Link diff --git a/feed_test.go b/feed_test.go index 74f7a71..21a171a 100644 --- a/feed_test.go +++ b/feed_test.go @@ -127,7 +127,7 @@ func TestFeed(t *testing.T) { }, &Item{ Title: "Never Gonna Give You Up Mp3", - Link: &Link{Href: "http://example.com/RickRoll.mp3",Length: 123456, Type: "audio/mpeg"}, + Link: &Link{Href: "http://example.com/RickRoll.mp3", Length: "123456", Type: "audio/mpeg"}, Description: "Never gonna give you up - Never gonna let you down.", Created: now, }, diff --git a/rss.go b/rss.go index b37b9cf..d1dfa6d 100644 --- a/rss.go +++ b/rss.go @@ -7,6 +7,7 @@ package feeds import ( "encoding/xml" "fmt" + "strconv" "time" ) @@ -76,7 +77,7 @@ type RssEnclosure struct { //RSS 2.0 XMLName xml.Name `xml:"enclosure"` Url string `xml:"url,attr"` - Length int64 `xml:"length,attr"` + Length string `xml:"length,attr"` Type string `xml:"type,attr"` } @@ -93,7 +94,10 @@ func newRssItem(i *Item) *RssItem { Guid: i.Id, PubDate: anyTimeFormat(time.RFC822, i.Created, i.Updated), } - if(i.Link.Length > 0 || i.Link.Type != ""){ + + int_Length, err := strconv.ParseInt(i.Link.Length, 10, 64) + + if err == nil && (int_Length > 0 || i.Link.Type != "") { item.Enclosure = &RssEnclosure{Url: i.Link.Href, Type: i.Link.Type, Length: i.Link.Length} } if i.Author != nil {