Clean up error handling of getEntriesForFeed

This commit is contained in:
Peter Stuifzand 2019-12-22 11:32:31 +01:00
parent 9dd00d29fd
commit 0be444aa29

14
main.go
View File

@ -1,6 +1,7 @@
package main
import (
"fmt"
"html/template"
"log"
"net/http"
@ -21,7 +22,10 @@ func main() {
log.Fatal(err)
}
items := getEntriesForFeed(u)
items, err := getEntriesForFeed(u)
if err != nil {
log.Fatal(err)
}
items = filterEntriesAfter(items, now.With(time.Now()).Monday())
@ -36,19 +40,19 @@ func main() {
}
}
func getEntriesForFeed(u *url.URL) []microsub.Item {
func getEntriesForFeed(u *url.URL) ([]microsub.Item, error) {
resp, err := http.Get(u.String())
if err != nil {
log.Fatal(err)
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
log.Fatalf("Status is not 200, but %d", resp.StatusCode)
return nil, fmt.Errorf("status is not 200, but %d", resp.StatusCode)
}
md := microformats.Parse(resp.Body, u)
items := jf2.SimplifyMicroformatDataItems(md)
return items
return items, nil
}
func filterEntriesAfter(items []microsub.Item, from time.Time) []microsub.Item {