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
import (
"encoding/json"
"fmt"
"net/http"
"time"
@ -126,20 +125,11 @@ func authenticate(c *gin.Context) {
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{
"success": true,
"message": "Authenticated",
"token": tokenString,
"user": response,
"user": user.User,
})
}
@ -387,18 +377,7 @@ func getUser(c *gin.Context) {
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{
"user": response,
})
c.JSON(http.StatusOK, gin.H{"user": user.User})
}
// DeleteUser godoc