diff options
author | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-01-28 21:14:27 +0300 |
---|---|---|
committer | Evgeny Kuznetsov <evgeny@kuznetsov.md> | 2020-01-28 21:14:27 +0300 |
commit | f3a4c3e464285abd5db211c047f16dbc5ce82c32 (patch) | |
tree | 5afe8f674bb0b8e4f718b4102c33f51feaa83799 /main.go | |
parent | 60d88d0bc841b1b48fd2a5262dc6723d63e4d641 (diff) | |
download | radiorus-rss-f3a4c3e464285abd5db211c047f16dbc5ce82c32.tar.gz radiorus-rss-f3a4c3e464285abd5db211c047f16dbc5ce82c32.zip |
improve test coverage
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -172,15 +172,22 @@ func populateFeed(feed *feeds.Feed, page []byte) (err error) { func describeFeed(feed *feeds.Feed, wg *sync.WaitGroup) { defer wg.Done() - programAboutUrl := strings.TrimSuffix(feed.Link.Href, "episodes") + "about" - page := getPage(programAboutUrl) - feed.Description = processFeedDesc(page) + url := strings.TrimSuffix(feed.Link.Href, "episodes") + "about" + page := getPage(url) + desc, err := processFeedDesc(page) + if err != nil { + log.Printf("could not find programme description on page %v: %v", url, err) + } + feed.Description = desc } -func processFeedDesc(page []byte) string { - programAbout := programAboutRe.FindSubmatch(page)[1] +func processFeedDesc(page []byte) (string, error) { + matches := programAboutRe.FindSubmatch(page) + if len(matches) < 2 { + return "", errCantParse + } re := regexp.MustCompile(`<(.+?)?>`) - return string(re.ReplaceAll(programAbout, []byte(``))) + return string(re.ReplaceAll(matches[1], []byte(``))), nil } func describeEpisodes(feed *feeds.Feed) { |