diff --git a/examples/StreamTracksToSpotifyPlaylist/main.go b/examples/StreamTracksToSpotifyPlaylist/main.go index 276f810..8476719 100644 --- a/examples/StreamTracksToSpotifyPlaylist/main.go +++ b/examples/StreamTracksToSpotifyPlaylist/main.go @@ -232,7 +232,8 @@ func writeResult(song audd.RecognitionResult) { return } req.Header.Set("Content-Type", "application/json") - _, err = spotifyClient.h.Do(req) + resp, err := spotifyClient.h.Do(req) + defer closeBody(resp) if capture(err) { return } @@ -241,6 +242,16 @@ func writeResult(song audd.RecognitionResult) { fmt.Printf("Added a song to the playlist (%s - %s, %s)\n", song.Artist, song.Title, song.SongLink) } +func closeBody(resp *http.Response) { + if resp == nil { + return + } + if resp.Body == nil { + return + } + _ = resp.Body.Close() +} + func capture(err error) bool { if err == nil { return false