diff --git a/cmd/root.go b/cmd/root.go index 9e230f8..547de10 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -37,12 +37,7 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) { return html.UnescapeString(b.String()), err } -func rssfetch(cmd *cobra.Command, urls []string) { - tmpl, err := template.New("out").Parse(output) - if err != nil { - log.Fatal(err) - } - +func parseFeeds(urls []string) []*gofeed.Feed { fp := gofeed.NewParser() var feedChs []chan *gofeed.Feed for _, url := range urls { @@ -62,6 +57,16 @@ func rssfetch(cmd *cobra.Command, urls []string) { feeds = append(feeds, <-feedCh) } + return feeds +} + +func rssfetch(cmd *cobra.Command, urls []string) { + tmpl, err := template.New("out").Parse(output) + if err != nil { + log.Fatal(err) + } + + feeds := parseFeeds(urls) for _, feed := range feeds { for _, item := range feed.Items { out, err := formatItem(item, tmpl)