Closed hxzqlh closed 5 years ago
resp <nil> Get https://hacker-news.firebaseio.com/v0/topstories.json: dial tcp 35.201.97.85:443: i/o timeout
The error shouldn't be ignored in getJSON
func, otherwise body
will be nil
:
// GetStories returns []int ids
func GetStories(target string) ([]int, error) {
var stories Ids
switch strings.ToLower(target) {
case "new", "top", "job", "ask":
body, _ := getJSON(apiEndpoint + target + "stories.json")
err := json.NewDecoder(body).Decode(&stories)
defer body.Close()
if err != nil {
return nil, err
}
}
return stories, nil
}
Should process the error when HTTP failed, fixed