From 6f965508b9742aa7bbd4f6d92c1c64d6339a62a4 Mon Sep 17 00:00:00 2001 From: Michael Handler Date: Mon, 9 Feb 2015 06:26:29 -0800 Subject: [PATCH] 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. --- testdata/handlers/handlerexample.go | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/testdata/handlers/handlerexample.go b/testdata/handlers/handlerexample.go index 8ce7fd0..26a6502 100644 --- a/testdata/handlers/handlerexample.go +++ b/testdata/handlers/handlerexample.go @@ -12,7 +12,7 @@ Build & run with: import ( "fmt" - rss "github.com/JalfResi/go-pkg-rss" + rss "github.com/jteeuwen/go-pkg-rss" "os" "time" ) @@ -26,7 +26,8 @@ func main() { func PollFeed(uri string, timeout int) { - feed := rss.NewWithHandler(timeout, true, rss.NewDatabaseHandler(NewMyHandler())) + handlers := &MyHandlers{} + feed := rss.NewWithHandlers(timeout, true, handlers, handlers) for { if err := feed.Fetch(uri, nil); err != nil { @@ -38,22 +39,12 @@ func PollFeed(uri string, timeout int) { } } -/* -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 MyHandlers struct{} -type MyHandler struct{} - -func NewMyHandler() rss.Handler { - return &MyHandler{} -} - -func (m *MyHandler) ProcessChannels(feed *rss.Feed, newchannels []*rss.Channel) { +func (m *MyHandlers) ProcessChannels(feed *rss.Feed, newchannels []*rss.Channel) { 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) }