diff --git a/feed/feed.go b/feed/feed.go new file mode 100644 index 0000000..6ebff70 --- /dev/null +++ b/feed/feed.go @@ -0,0 +1,10 @@ +package feed + +import ( + "github.com/SlyMarbo/rss" +) + +type Feed struct { + URL string + ItemHandler func(*rss.Item) string +} diff --git a/main.go b/main.go index 87b0119..da04bd4 100644 --- a/main.go +++ b/main.go @@ -5,15 +5,10 @@ import ( "os" "plugin" "reflect" - + "github.com/haarts/golang_news/feed" "github.com/SlyMarbo/rss" ) -type Feed struct { - URL string - ItemHandler func(*rss.Item) string -} - func main() { log.SetOutput(os.Stdout) log.Println("Starting") @@ -28,7 +23,7 @@ func main() { postTweets(tweets) } -func feeds() ([]Feed, error) { +func feeds() ([]feed.Feed, error) { p, err := plugin.Open(os.Args[1]) if err != nil { log.Printf("Error reading plugin: %s", err) @@ -40,10 +35,10 @@ func feeds() ([]Feed, error) { return nil, err } - return listFunc.(func() []Feed)(), nil + return listFunc.(func() []feed.Feed)(), nil } -func pollFeeds(publishTweet chan string, feeds []Feed) { +func pollFeeds(publishTweet chan string, feeds []feed.Feed) { itemProducers := []chan *rss.Item{} for _, feed := range feeds { itemProducer := make(chan *rss.Item) diff --git a/plugins/julialang_news/main.go b/plugins/julialang_news/main.go index d0d248e..935087f 100644 --- a/plugins/julialang_news/main.go +++ b/plugins/julialang_news/main.go @@ -5,28 +5,22 @@ import ( "log" "regexp" + "github.com/haarts/golang_news/feed" "github.com/SlyMarbo/rss" ) -type Feed struct { - URL string - ItemHandler func(*rss.Item) string -} -func List() []Feed { - return []Feed{ - Feed{ + +func List() []feed.Feed { + return []feed.Feed{ + feed.Feed{ URL: "http://www.juliabloggers.com/feed/", ItemHandler: blogItem, }, - Feed{ + feed.Feed{ URL: "https://news.ycombinator.com/rss", ItemHandler: hnItem, }, - Feed{ - URL: "https://www.reddit.com/r/julia.rss", - ItemHandler: redditItem, - }, } }