encodable a good

Former-commit-id: a0afebd82dfd256ec70c02c607af2a9b3b4b046f
This commit is contained in:
bel
2019-06-22 08:58:54 -06:00
parent 730cf1e15a
commit be065c5dcb
12 changed files with 260 additions and 86 deletions

44
rss/rss.go Normal file
View 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
}