Makes atom replace channels and items, thus making it stateless

This commit is contained in:
Harm Aarts 2013-12-05 14:08:41 +01:00
parent 6ef84d35e2
commit 73442f806a
1 changed files with 4 additions and 20 deletions

24
atom.go
View File

@ -6,32 +6,15 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
ns := "http://www.w3.org/2005/Atom" ns := "http://www.w3.org/2005/Atom"
channels := doc.SelectNodes(ns, "feed") channels := doc.SelectNodes(ns, "feed")
getChan := func(id, title string) *Channel { var foundChannels []*Channel
for _, c := range this.Channels {
switch {
case len(id) > 0:
if c.Id == id {
return c
}
case len(title) > 0:
if c.Title == title {
return c
}
}
}
return nil
}
var ch *Channel var ch *Channel
var i *Item var i *Item
var tn *xmlx.Node var tn *xmlx.Node
var list []*xmlx.Node var list []*xmlx.Node
for _, node := range channels { for _, node := range channels {
if ch = getChan(node.S(ns, "id"), node.S(ns, "title")); ch == nil { ch = new(Channel)
ch = new(Channel) foundChannels = append(foundChannels, ch)
this.Channels = append(this.Channels, ch)
}
ch.Title = node.S(ns, "title") ch.Title = node.S(ns, "title")
ch.LastBuildDate = node.S(ns, "updated") ch.LastBuildDate = node.S(ns, "updated")
@ -121,5 +104,6 @@ func (this *Feed) readAtom(doc *xmlx.Document) (err error) {
this.itemhandler(this, ch, ch.Items[itemcount:]) this.itemhandler(this, ch, ch.Items[itemcount:])
} }
} }
this.Channels = foundChannels
return return
} }