RssEnclosure.Length remains string to not break the API

code now gofmt formatted
This commit is contained in:
Paul Petring
2015-08-08 17:50:08 +02:00
parent 83d205214a
commit e2bd4557b0
4 changed files with 14 additions and 12 deletions
+6 -6
View File
@@ -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}}
+1 -3
View File
@@ -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
+1 -1
View File
@@ -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,
},
+6 -2
View File
@@ -7,6 +7,7 @@ package feeds
import (
"encoding/xml"
"fmt"
"strconv"
"time"
)
@@ -76,7 +77,7 @@ type RssEnclosure struct {
//RSS 2.0 <enclosure url="http://example.com/file.mp3" length="123456789" type="audio/mpeg" />
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 {