Hello!
I am writing a simple REST API with this library. So far it works as expected but I am now running into (more of a beauty) error.
var login LOGIN
if err := c.BindJSON(&login); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": gin.H{"code": http.StatusBadRequest, "message": "Bad Request"}})
log.Error().Err(err).Msg("BindJSON Failed")
return
}
If I use this code, the content-type is text/plain. This happens even if I set c.Header("Content-Type", "application/json")
.
In any other code I build so far the c.JSON sets the correct type.
Is this a known error or am I missing something?
Kindly
Comment From: joosejunsheng
Don't see any issue from the codes. c.JSON automatically sets Content-Type to application/json by default. https://github.com/gin-gonic/gin/blob/3b28645dc95d58e0df36b8aff7a6c64f7c0ca5e9/render/json.go#L61