Skip to content

Instantly share code, notes, and snippets.

@jonathan-fielding
Created January 12, 2021 22:06
Show Gist options
  • Save jonathan-fielding/fb987d89b86463450cb0c31578e26ec7 to your computer and use it in GitHub Desktop.
Save jonathan-fielding/fb987d89b86463450cb0c31578e26ec7 to your computer and use it in GitHub Desktop.
func response(w http.ResponseWriter, req *http.Request) {
resp, err := http.Get("https://cat-fact.herokuapp.com/facts/random?amount=1")
if err != nil {
panic(err)
}
defer resp.Body.Close()
var catfacts CatFacts
json.NewDecoder(resp.Body).Decode(&catfacts)
fmt.Fprintf(w, catfacts.Text)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment