From a9e9a5d0235248344cf3ec0cbfb295a4dd68dc2a Mon Sep 17 00:00:00 2001 From: AustrianToast Date: Fri, 23 Feb 2024 23:25:55 +0100 Subject: [PATCH] tiny performance increase switched from IndendetJSON to JSON this increases performance --- main.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/main.go b/main.go index cc260a8..bfe3ea7 100644 --- a/main.go +++ b/main.go @@ -39,7 +39,7 @@ func main() { // getAlbums responds with the list of all albums as JSON. func getAlbums(c *gin.Context) { - c.IndentedJSON(http.StatusOK, albums) + c.JSON(http.StatusOK, albums) } // postAlbums adds an album from JSON received in the request body. @@ -74,16 +74,16 @@ func getAlbumByID(c *gin.Context) { // an album whose ID value matches the parameter. for _, a := range albums { if a.ID == id { - c.IndentedJSON(http.StatusOK, a) + c.JSON(http.StatusOK, a) return } } - c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"}) + c.JSON(http.StatusNotFound, gin.H{"message": "album not found"}) } func delAlbums(c *gin.Context) { albums = []album{} - c.IndentedJSON(http.StatusOK, albums) + c.JSON(http.StatusOK, albums) } func delAlbumByID(c *gin.Context) { @@ -92,11 +92,11 @@ func delAlbumByID(c *gin.Context) { for s, a := range albums { if a.ID == id { albums = remove(albums, s) - c.IndentedJSON(http.StatusOK, albums) + c.JSON(http.StatusCreated, albums) return } } - c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"}) + c.JSON(http.StatusNotFound, gin.H{"message": "album not found"}) } func updateAlbum(c *gin.Context) { @@ -112,9 +112,9 @@ func updateAlbum(c *gin.Context) { if a.ID == id { albums = remove(albums, s) albums = append(albums, newAlbum) - c.IndentedJSON(http.StatusOK, newAlbum) + c.JSON(http.StatusCreated, newAlbum) return } } - c.IndentedJSON(http.StatusNotFound, gin.H{"message": "album not found"}) + c.JSON(http.StatusNotFound, gin.H{"message": "album not found"}) }