Created
January 12, 2021 22:06
-
-
Save jonathan-fielding/fb987d89b86463450cb0c31578e26ec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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