set slice lengths at creation
This commit is contained in:
parent
7d2d4f0960
commit
34abeeb37b
18
cmd/root.go
18
cmd/root.go
|
@ -41,10 +41,10 @@ func formatItem(item *gofeed.Item, tmpl *template.Template) (string, error) {
|
||||||
// along with any parsing errors.
|
// along with any parsing errors.
|
||||||
func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
|
func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
|
||||||
fp := gofeed.NewParser()
|
fp := gofeed.NewParser()
|
||||||
var feedChs []chan *gofeed.Feed
|
feedChs := make([]chan *gofeed.Feed, len(urls))
|
||||||
var errChs []chan error
|
errChs := make([]chan error, len(urls))
|
||||||
|
|
||||||
for _, url := range urls {
|
for i, url := range urls {
|
||||||
feedCh := make(chan *gofeed.Feed)
|
feedCh := make(chan *gofeed.Feed)
|
||||||
errCh := make(chan error)
|
errCh := make(chan error)
|
||||||
go func(url string) {
|
go func(url string) {
|
||||||
|
@ -52,15 +52,15 @@ func parseFeeds(urls []string) ([]*gofeed.Feed, []error) {
|
||||||
feedCh <- feed
|
feedCh <- feed
|
||||||
errCh <- err
|
errCh <- err
|
||||||
}(url)
|
}(url)
|
||||||
feedChs = append(feedChs, feedCh)
|
feedChs[i] = feedCh
|
||||||
errChs = append(errChs, errCh)
|
errChs[i] = errCh
|
||||||
}
|
}
|
||||||
|
|
||||||
var feeds []*gofeed.Feed
|
feeds := make([]*gofeed.Feed, len(urls))
|
||||||
var errs []error
|
errs := make([]error, len(urls))
|
||||||
for i := range feedChs {
|
for i := range feedChs {
|
||||||
feeds = append(feeds, <-feedChs[i])
|
feeds[i] = <-feedChs[i]
|
||||||
errs = append(errs, <-errChs[i])
|
errs[i] = <-errChs[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
return feeds, errs
|
return feeds, errs
|
||||||
|
|
Loading…
Reference in New Issue