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.
|
// getAlbums responds with the list of all albums as JSON.
|
||||||
func getAlbums(c *gin.Context) {
|
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.
|
// 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.
|
// an album whose ID value matches the parameter.
|
||||||
for _, a := range albums {
|
for _, a := range albums {
|
||||||
if a.ID == id {
|
if a.ID == id {
|
||||||
c.IndentedJSON(http.StatusOK, a)
|
c.JSON(http.StatusOK, a)
|
||||||
return
|
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) {
|
func delAlbums(c *gin.Context) {
|
||||||
albums = []album{}
|
albums = []album{}
|
||||||
c.IndentedJSON(http.StatusOK, albums)
|
c.JSON(http.StatusOK, albums)
|
||||||
}
|
}
|
||||||
|
|
||||||
func delAlbumByID(c *gin.Context) {
|
func delAlbumByID(c *gin.Context) {
|
||||||
@ -92,11 +92,11 @@ func delAlbumByID(c *gin.Context) {
|
|||||||
for s, a := range albums {
|
for s, a := range albums {
|
||||||
if a.ID == id {
|
if a.ID == id {
|
||||||
albums = remove(albums, s)
|
albums = remove(albums, s)
|
||||||
c.IndentedJSON(http.StatusOK, albums)
|
c.JSON(http.StatusCreated, albums)
|
||||||
return
|
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) {
|
func updateAlbum(c *gin.Context) {
|
||||||
@ -112,9 +112,9 @@ func updateAlbum(c *gin.Context) {
|
|||||||
if a.ID == id {
|
if a.ID == id {
|
||||||
albums = remove(albums, s)
|
albums = remove(albums, s)
|
||||||
albums = append(albums, newAlbum)
|
albums = append(albums, newAlbum)
|
||||||
c.IndentedJSON(http.StatusOK, newAlbum)
|
c.JSON(http.StatusCreated, newAlbum)
|
||||||
return
|
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