tiny performance increase

switched from IndendetJSON to JSON
this increases performance
This commit is contained in:
AustrianToast 2024-02-23 23:25:55 +01:00
parent c61affb36e
commit a9e9a5d023
No known key found for this signature in database
GPG Key ID: 5CD422268E489EB4

16
main.go
View File

@ -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"})
}