return errors from helper function
This commit is contained in:
parent
b331955266
commit
77fd6b33ad
32
cmd/root.go
32
cmd/root.go
|
@ -37,27 +37,31 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) {
|
||||||
return html.UnescapeString(b.String()), err
|
return html.UnescapeString(b.String()), err
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseFeeds(urls []string) []*gofeed.Feed {
|
func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
|
||||||
fp := gofeed.NewParser()
|
fp := gofeed.NewParser()
|
||||||
var feedChs []chan *gofeed.Feed
|
var feedChs []chan *gofeed.Feed
|
||||||
|
var errChs []chan error
|
||||||
|
|
||||||
for _, url := range urls {
|
for _, url := range urls {
|
||||||
ch := make(chan *gofeed.Feed)
|
feedCh := make(chan *gofeed.Feed)
|
||||||
|
errCh := make(chan error)
|
||||||
go func(url string) {
|
go func(url string) {
|
||||||
feed, err := fp.ParseURL(url)
|
feed, err := fp.ParseURL(url)
|
||||||
if err != nil {
|
feedCh <- feed
|
||||||
log.Fatal(err)
|
errCh <- err
|
||||||
}
|
|
||||||
ch <- feed
|
|
||||||
}(url)
|
}(url)
|
||||||
feedChs = append(feedChs, ch)
|
feedChs = append(feedChs, feedCh)
|
||||||
|
errChs = append(errChs, errCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
var feeds []*gofeed.Feed
|
var feeds []*gofeed.Feed
|
||||||
for _, feedCh := range feedChs {
|
var errs []error
|
||||||
feeds = append(feeds, <-feedCh)
|
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) {
|
func rssfetch(cmd *cobra.Command, urls []string) {
|
||||||
|
@ -66,7 +70,13 @@ func rssfetch(cmd *cobra.Command, urls []string) {
|
||||||
log.Fatal(err)
|
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 _, feed := range feeds {
|
||||||
for _, item := range feed.Items {
|
for _, item := range feed.Items {
|
||||||
out, err := formatItem(item, tmpl)
|
out, err := formatItem(item, tmpl)
|
||||||
|
|
Loading…
Reference in New Issue