Fix bug of User marshaling:

Instead of using the json.Marshal() we can user `gin.H` type of the
    response that will be passed through an XMLMarshaler. In that case
    we don't even need the responses structs!!
This commit is contained in:
smavros 2019-08-13 16:20:58 +02:00
parent 28d81e52c2
commit 42f473cde0

View file

@ -1,7 +1,6 @@
package user package user
import ( import (
"encoding/json"
"fmt" "fmt"
"net/http" "net/http"
"time" "time"
@ -126,20 +125,11 @@ func authenticate(c *gin.Context) {
return return
} }
response, err := json.Marshal(common.ResponseMsgUser{user.User})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"message": fmt.Sprintf("%v", err),
})
return
}
c.JSON(http.StatusOK, gin.H{ c.JSON(http.StatusOK, gin.H{
"success": true, "success": true,
"message": "Authenticated", "message": "Authenticated",
"token": tokenString, "token": tokenString,
"user": response, "user": user.User,
}) })
} }
@ -387,18 +377,7 @@ func getUser(c *gin.Context) {
return return
} }
response, err := json.Marshal(common.ResponseMsgUser{user.User}) c.JSON(http.StatusOK, gin.H{"user": user.User})
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{
"success": false,
"message": fmt.Sprintf("%v", err),
})
return
}
c.JSON(http.StatusOK, gin.H{
"user": response,
})
} }
// DeleteUser godoc // DeleteUser godoc