Skip to content

Commit

Permalink
Split of Feed into own package
Browse files Browse the repository at this point in the history
That package can now be shared.
  • Loading branch information
haarts committed Jun 11, 2019
1 parent f4451e7 commit 29695bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
10 changes: 10 additions & 0 deletions feed/feed.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package feed

import (
"github.com/SlyMarbo/rss"
)

type Feed struct {
URL string
ItemHandler func(*rss.Item) string
}
13 changes: 4 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
Expand Down
18 changes: 6 additions & 12 deletions plugins/julialang_news/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}
}

Expand Down

0 comments on commit 29695bd

Please sign in to comment.