From d38fef3be25a625ba686d41b6b8779f809373456 Mon Sep 17 00:00:00 2001
From: froge <froge@git.repo.cafe>
Date: Fri, 14 Feb 2025 12:42:01 +1000
Subject: [PATCH] Clean up comments and defer response body closing

---
 routes.go | 2 +-
 utils.go  | 5 +----
 2 files changed, 2 insertions(+), 5 deletions(-)

diff --git a/routes.go b/routes.go
index f664dd2..e58ba78 100644
--- a/routes.go
+++ b/routes.go
@@ -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")
diff --git a/utils.go b/utils.go
index e32a4d9..0dc1e37 100644
--- a/utils.go
+++ b/utils.go
@@ -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