I’m trying to unmarshal a request using c.ShouldBindBodyWith(&UserObj, binding.JSON).
I’m using the below structs:
type User struct {
Name string `json:"name" binding:"required"`
Age uint `json:"age" binding:"required"`
Comments []*Comment `json:"comments"`
}
type Comment struct {
Text string `json:"text" binding:"required"`
Len uint `json:"type" binding:"required"`
}
When I send a request with missing Text field or missing Len field in Comment, it should return an error. But this isn’t happening.
Any suggestions?
New contributor
Go guy is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.