return errors from helper function

This commit is contained in:
filifa 2024-06-18 19:20:09 -05:00
parent b331955266
commit 77fd6b33ad
1 changed files with 21 additions and 11 deletions

View File

@ -37,27 +37,31 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) {
return html.UnescapeString(b.String()), err
}
func parseFeeds(urls []string) []*gofeed.Feed {
func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
fp := gofeed.NewParser()
var feedChs []chan *gofeed.Feed
var errChs []chan error
for _, url := range urls {
ch := make(chan *gofeed.Feed)
feedCh := make(chan *gofeed.Feed)
errCh := make(chan error)
go func(url string) {
feed, err := fp.ParseURL(url)
if err != nil {
log.Fatal(err)
}
ch <- feed
feedCh <- feed
errCh <- err
}(url)
feedChs = append(feedChs, ch)
feedChs = append(feedChs, feedCh)
errChs = append(errChs, errCh)
}
var feeds []*gofeed.Feed
for _, feedCh := range feedChs {
feeds = append(feeds, <-feedCh)
var errs []error
for i := range feedChs {
feeds = append(feeds, <-feedChs[i])
errs = append(errs, <-errChs[i])
}
return feeds
return feeds, errs
}
func rssfetch(cmd *cobra.Command, urls []string) {
@ -66,7 +70,13 @@ func rssfetch(cmd *cobra.Command, urls []string) {
log.Fatal(err)
}
feeds := parseFeeds(urls)
feeds, errs := parseFeeds(urls)
for _, err := range errs {
if err != nil {
log.Fatal(err)
}
}
for _, feed := range feeds {
for _, item := range feed.Items {
out, err := formatItem(item, tmpl)