encodable a good
Former-commit-id: a0afebd82dfd256ec70c02c607af2a9b3b4b046f
This commit is contained in:
44
rss/rss.go
Normal file
44
rss/rss.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package rss
|
||||
|
||||
import (
|
||||
"local/rssmon3/config"
|
||||
"local/rssmon3/monitor"
|
||||
"log"
|
||||
)
|
||||
|
||||
const nsFeeds = "nsFeeds"
|
||||
|
||||
type RSS struct {
|
||||
items chan *monitor.Item
|
||||
config.Stoppable
|
||||
}
|
||||
|
||||
func New(items chan *monitor.Item) *RSS {
|
||||
return &RSS{
|
||||
items: items,
|
||||
}
|
||||
}
|
||||
|
||||
func (rss *RSS) Run() error {
|
||||
for {
|
||||
select {
|
||||
case <-rss.Stopped():
|
||||
return nil
|
||||
case i := <-rss.items:
|
||||
if err := rss.update(i); err != nil {
|
||||
log.Println(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (rss *RSS) update(item *monitor.Item) error {
|
||||
f := newFeed(item.Key)
|
||||
if err := f.pull(); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := f.save(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user