for learning purposes I'm building a command line tool using golang, this cli fetches the top ten posts from GameDeals subreddit using the following api:
https://www.reddit.com/r/gamedeals/hot.json?limit=10
When I send the request I got as response a 503 Service Unavailable and some HTML:
<img src=//s3.amazonaws.com/redditstatic/heavy-load.png alt="">
<h2>Our CDN was unable to reach our servers</h2>
Please check <a href="http://www.redditstatus.com/">www.redditstatus.com</a> if you consistently get this error.
I don't understand why if I fires the request from a browser I got the json expected and instead a 503 error from my cli.
Here's my code that performs the request:
address := fmt.Sprintf("%s/hot.json?limit=%d", redditBaseURL, 10)
req, err := http.NewRequest("get", address, nil)
if err != nil {
return err
}
req.Header.Set("User-Agent", userAgent)
res, err := client.Do(req)
if err != nil {
return err
}
defer res.Body.Close()
result, err := ioutil.ReadAll(res.Body)
if err != nil {
return err
}
fmt.Println(string(result))
Am I missing something?