Last active
October 16, 2018 18:21
-
-
Save koral--/fd784e2ef4c482bf1c4940010193ee55 to your computer and use it in GitHub Desktop.
Downloading Chuck Norris joke as a plain text
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 getRandomJoke(config Config) (string, error) { | |
request, err := buildJokeRequest(config) | |
if err != nil { | |
return "", err | |
} | |
response, err := getJoke(request) | |
if err != nil { | |
return "", err | |
} | |
defer func() { | |
if err := response.Body.Close(); err != nil { | |
log.Warnf("Failed to close response body, error: %s", err) | |
} | |
}() | |
return readJokeFromResponse(response) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment