Clean up comments and defer response body closing

This commit is contained in:
froge 2025-02-14 12:42:01 +10:00
parent 48bf0df6d4
commit d38fef3be2
Signed by: froge
GPG key ID: A825E09930271BFA
2 changed files with 2 additions and 5 deletions

View file

@ -10,7 +10,7 @@ import (
)
// Pagination helper middleware
// This just checks and inserts some default pagination values
// This just checks and inserts some default pagination values into the request context
func paginator() gin.HandlerFunc {
return func(c *gin.Context) {
queryPage := c.DefaultQuery("page", "1")

View file

@ -38,7 +38,6 @@ func getSpotifyArtistData(artistID string, spotifyAuthToken string) (SpotifyResp
}
req.Header.Add("Authorization", spotifyAuthToken)
// Send off request
resp, err := http.DefaultClient.Do(req)
if err != nil {
respErr := &ResponseError{
@ -53,6 +52,7 @@ func getSpotifyArtistData(artistID string, spotifyAuthToken string) (SpotifyResp
}
return SpotifyResponse{}, respErr
}
defer resp.Body.Close()
var spotifyResponse SpotifyResponse
err = json.NewDecoder(resp.Body).Decode(&spotifyResponse)
@ -64,9 +64,6 @@ func getSpotifyArtistData(artistID string, spotifyAuthToken string) (SpotifyResp
return SpotifyResponse{}, respErr
}
// Close this immediately since it's unused now
resp.Body.Close()
// After all the above checks we assume this response is populated
// If errors arise we can do extra validation here
return spotifyResponse, nil