Channel and Item handler example cleanups
* Don't import from a forked repo in the sample code. * Repair the sample to work with the current handler interface.
This commit is contained in:
parent
975dd7ebf4
commit
6f965508b9
|
@ -12,7 +12,7 @@ Build & run with:
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
rss "github.com/JalfResi/go-pkg-rss"
|
rss "github.com/jteeuwen/go-pkg-rss"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +26,8 @@ func main() {
|
||||||
|
|
||||||
func PollFeed(uri string, timeout int) {
|
func PollFeed(uri string, timeout int) {
|
||||||
|
|
||||||
feed := rss.NewWithHandler(timeout, true, rss.NewDatabaseHandler(NewMyHandler()))
|
handlers := &MyHandlers{}
|
||||||
|
feed := rss.NewWithHandlers(timeout, true, handlers, handlers)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if err := feed.Fetch(uri, nil); err != nil {
|
if err := feed.Fetch(uri, nil); err != nil {
|
||||||
|
@ -38,22 +39,12 @@ func PollFeed(uri string, timeout int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
type MyHandlers struct{}
|
||||||
func itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) {
|
|
||||||
fmt.Printf("%d new item(s) in %s\n", len(newitems), feed.Url)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
type MyHandler struct{}
|
func (m *MyHandlers) ProcessChannels(feed *rss.Feed, newchannels []*rss.Channel) {
|
||||||
|
|
||||||
func NewMyHandler() rss.Handler {
|
|
||||||
return &MyHandler{}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (m *MyHandler) ProcessChannels(feed *rss.Feed, newchannels []*rss.Channel) {
|
|
||||||
fmt.Printf("%d new channel(s) in %s\n", len(newchannels), feed.Url)
|
fmt.Printf("%d new channel(s) in %s\n", len(newchannels), feed.Url)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *MyHandler) ProcessItems(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) {
|
func (m *MyHandlers) ProcessItems(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) {
|
||||||
fmt.Printf("%d new rad item(s) in %s\n", len(newitems), feed.Url)
|
fmt.Printf("%d new rad item(s) in %s\n", len(newitems), feed.Url)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue