Updated code to conform with more recent go idioms.
This commit is contained in:
parent
49ab919bd7
commit
365cffa6a4
|
@ -20,7 +20,6 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err os.Error) {
|
|||
ch.Links[i].Rel = v.GetAttr("", "rel")
|
||||
ch.Links[i].Type = v.GetAttr("", "type")
|
||||
ch.Links[i].HrefLang = v.GetAttr("", "hreflang")
|
||||
|
||||
}
|
||||
|
||||
tn := node.SelectNode(ns, "subtitle")
|
||||
|
|
|
@ -30,20 +30,15 @@ type Channel struct {
|
|||
}
|
||||
|
||||
func (this *Channel) addItem(item Item) {
|
||||
slice := make([]Item, len(this.Items)+1)
|
||||
for i, v := range this.Items {
|
||||
slice[i] = v
|
||||
}
|
||||
slice[len(slice)-1] = item
|
||||
this.Items = slice
|
||||
c := make([]Item, len(this.Items)+1)
|
||||
copy(c, this.Items)
|
||||
c[len(c)-1] = item
|
||||
this.Items = c
|
||||
}
|
||||
|
||||
|
||||
func (this *Channel) addLink(l Link) {
|
||||
slice := make([]Link, len(this.Links)+1)
|
||||
for i, v := range this.Links {
|
||||
slice[i] = v
|
||||
}
|
||||
slice[len(slice)-1] = l
|
||||
this.Links = slice
|
||||
c := make([]Link, len(this.Links)+1)
|
||||
copy(c, this.Links)
|
||||
c[len(c)-1] = l
|
||||
this.Links = c
|
||||
}
|
||||
|
|
10
src/feed.go
10
src/feed.go
|
@ -74,12 +74,10 @@ func New(cachetimeout int, enforcecachelimit bool) *Feed {
|
|||
}
|
||||
|
||||
func (this *Feed) addChannel(ch Channel) {
|
||||
slice := make([]Channel, len(this.Channels)+1)
|
||||
for i, v := range this.Channels {
|
||||
slice[i] = v
|
||||
}
|
||||
slice[len(slice)-1] = ch
|
||||
this.Channels = slice
|
||||
c := make([]Channel, len(this.Channels)+1)
|
||||
copy(c, this.Channels)
|
||||
c[len(c)-1] = ch
|
||||
this.Channels = c
|
||||
}
|
||||
|
||||
func (this *Feed) Fetch(uri string) (err os.Error) {
|
||||
|
|
|
@ -10,12 +10,14 @@ func TestFeed(t *testing.T) {
|
|||
"http://blog.case.edu/news/feed.atom",
|
||||
}
|
||||
|
||||
var feed *Feed
|
||||
var err os.Error
|
||||
|
||||
for _, uri := range urilist {
|
||||
feed := New(5, true)
|
||||
err := feed.Fetch(uri)
|
||||
if err != nil {
|
||||
feed = New(5, true)
|
||||
|
||||
if err = feed.Fetch(uri); err != nil {
|
||||
t.Errorf("%s >>> %s", uri, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
20
src/item.go
20
src/item.go
|
@ -21,19 +21,15 @@ type Item struct {
|
|||
}
|
||||
|
||||
func (this *Item) addEnclosure(e Enclosure) {
|
||||
slice := make([]Enclosure, len(this.Enclosures)+1)
|
||||
for i, v := range this.Enclosures {
|
||||
slice[i] = v
|
||||
}
|
||||
slice[len(slice)-1] = e
|
||||
this.Enclosures = slice
|
||||
c := make([]Enclosure, len(this.Enclosures)+1)
|
||||
copy(c, this.Enclosures)
|
||||
c[len(c)-1] = e
|
||||
this.Enclosures = c
|
||||
}
|
||||
|
||||
func (this *Item) addLink(l Link) {
|
||||
slice := make([]Link, len(this.Links)+1)
|
||||
for i, v := range this.Links {
|
||||
slice[i] = v
|
||||
}
|
||||
slice[len(slice)-1] = l
|
||||
this.Links = slice
|
||||
c := make([]Link, len(this.Links)+1)
|
||||
copy(c, this.Links)
|
||||
c[len(c)-1] = l
|
||||
this.Links = c
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue