Updated code to conform with more recent go idioms.

This commit is contained in:
jim teeuwen 2010-05-26 01:41:44 +02:00
parent 49ab919bd7
commit 365cffa6a4
5 changed files with 26 additions and 36 deletions

View File

@ -20,7 +20,6 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
ch.Links[i].Rel = v.GetAttr("", "rel") ch.Links[i].Rel = v.GetAttr("", "rel")
ch.Links[i].Type = v.GetAttr("", "type") ch.Links[i].Type = v.GetAttr("", "type")
ch.Links[i].HrefLang = v.GetAttr("", "hreflang") ch.Links[i].HrefLang = v.GetAttr("", "hreflang")
} }
tn := node.SelectNode(ns, "subtitle") tn := node.SelectNode(ns, "subtitle")

View File

@ -30,20 +30,15 @@ type Channel struct {
} }
func (this *Channel) addItem(item Item) { func (this *Channel) addItem(item Item) {
slice := make([]Item, len(this.Items)+1) c := make([]Item, len(this.Items)+1)
for i, v := range this.Items { copy(c, this.Items)
slice[i] = v c[len(c)-1] = item
} this.Items = c
slice[len(slice)-1] = item
this.Items = slice
} }
func (this *Channel) addLink(l Link) { func (this *Channel) addLink(l Link) {
slice := make([]Link, len(this.Links)+1) c := make([]Link, len(this.Links)+1)
for i, v := range this.Links { copy(c, this.Links)
slice[i] = v c[len(c)-1] = l
} this.Links = c
slice[len(slice)-1] = l
this.Links = slice
} }

View File

@ -74,12 +74,10 @@ func New(cachetimeout int, enforcecachelimit bool) *Feed {
} }
func (this *Feed) addChannel(ch Channel) { func (this *Feed) addChannel(ch Channel) {
slice := make([]Channel, len(this.Channels)+1) c := make([]Channel, len(this.Channels)+1)
for i, v := range this.Channels { copy(c, this.Channels)
slice[i] = v c[len(c)-1] = ch
} this.Channels = c
slice[len(slice)-1] = ch
this.Channels = slice
} }
func (this *Feed) Fetch(uri string) (err os.Error) { func (this *Feed) Fetch(uri string) (err os.Error) {

View File

@ -10,12 +10,14 @@ func TestFeed(t *testing.T) {
"http://blog.case.edu/news/feed.atom", "http://blog.case.edu/news/feed.atom",
} }
var feed *Feed
var err os.Error
for _, uri := range urilist { for _, uri := range urilist {
feed := New(5, true) feed = New(5, true)
err := feed.Fetch(uri)
if err != nil { if err = feed.Fetch(uri); err != nil {
t.Errorf("%s >>> %s", uri, err) t.Errorf("%s >>> %s", uri, err)
continue
} }
} }
} }

View File

@ -21,19 +21,15 @@ type Item struct {
} }
func (this *Item) addEnclosure(e Enclosure) { func (this *Item) addEnclosure(e Enclosure) {
slice := make([]Enclosure, len(this.Enclosures)+1) c := make([]Enclosure, len(this.Enclosures)+1)
for i, v := range this.Enclosures { copy(c, this.Enclosures)
slice[i] = v c[len(c)-1] = e
} this.Enclosures = c
slice[len(slice)-1] = e
this.Enclosures = slice
} }
func (this *Item) addLink(l Link) { func (this *Item) addLink(l Link) {
slice := make([]Link, len(this.Links)+1) c := make([]Link, len(this.Links)+1)
for i, v := range this.Links { copy(c, this.Links)
slice[i] = v c[len(c)-1] = l
} this.Links = c
slice[len(slice)-1] = l
this.Links = slice
} }