Makes atom replace channels and items, thus making it stateless
This commit is contained in:
parent
6ef84d35e2
commit
73442f806a
22
atom.go
22
atom.go
|
@ -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)
|
||||||
this.Channels = append(this.Channels, ch)
|
foundChannels = append(foundChannels, 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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue