Skip to content

Commit

Permalink
support customized http client to download feed.
Browse files Browse the repository at this point in the history
  • Loading branch information
hippasus committed Mar 15, 2014
1 parent a8f6f4b commit 4790aab
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion rss.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,22 @@ func CacheParsedItemIDs(flag bool) (didCache bool) {
return
}

type FetchFunc func() (resp *http.Response, err error)

// Fetch downloads and parses the RSS feed at the given URL
func Fetch(url string) (*Feed, error) {
resp, err := http.Get(url)
return FetchByClient(url, http.DefaultClient)
}

func FetchByClient(url string, client *http.Client) (*Feed, error) {
fetchFunc := func() (resp *http.Response, err error) {
return client.Get(url)
}
return FetchByFunc(fetchFunc, url)
}

func FetchByFunc(fetchFunc FetchFunc, url string) (*Feed, error) {
resp, err := fetchFunc()
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 4790aab

Please sign in to comment.