Skip to content

Commit

Permalink
Introduce a timeout when fetching article urls
Browse files Browse the repository at this point in the history
  • Loading branch information
heussd committed May 4, 2024
1 parent df9a660 commit 40e1f05
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion rss-article-url-feeder-go/internal/feed/feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package feed
import (
"fmt"
"github.com/SlyMarbo/rss"
"net/http"
"net/url"
"strings"
"time"
Expand All @@ -21,10 +22,17 @@ func getBaseUrl(s string) string {
return u.String()
}

var TimeoutFetchFunc = func(url string) (resp *http.Response, err error) {
var client = &http.Client{
Timeout: time.Second * 60,
}
return client.Get(url)
}

func ArticleUrls(feedUrl string) []string {
var articleUrls []string

feed, err := rss.Fetch(feedUrl)
feed, err := rss.FetchByFunc(TimeoutFetchFunc, feedUrl)
if err != nil {
fmt.Printf("❌️ %s failed to load: %s\n", feedUrl, err)
return articleUrls
Expand Down

0 comments on commit 40e1f05

Please sign in to comment.