tiny performance increase
switched from IndendetJSON to JSON this increases performance
This commit is contained in:
parent
c61affb36e
commit
a9e9a5d023
16
main.go
16
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"})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user