-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error() prints too many end-lines #44
Comments
I agree this makes sense for logging, I will remove the line breaks. I do however feel the need to point out that, like the documentation states, these errors are intended for debugging and not production error messages. For example the end user would probably want to see the error
Instead of
|
I am working in a complete integration with gin, this is a automatic generated error JSON. {
"error":"Struct:JSON\nField validation for \"Title\" failed on the \"required\" tag\nField validation for \"Description\" failed on the \"required\" tag\nField validation for \"Body\" failed on the \"required\" tag\n\n\n",
"fields":[
"title",
"description",
"body"
],
"message":"title, description and body are required."
} what do you think? type JSON struct {
Title string `binding:"required"`
Description string `binding:"required"`
Body string `binding:"required"`
}
func main() {
router := gin.Default()
router.Use(gin.ErrorLogger())
router.POST("/", func(c *gin.Context) {
var json JSON
if c.BindJSON(&json) == nil {
// read json safely
}
})
router.Run(":8080")
} |
I am working on this and a few other things and should be completed within the next few hours. the fix removes the extra 3 \n's |
@joeybloggs nice! |
offtopic: I love the new v5 API. nice work! |
thanks @manucorporat I'll take a look |
nice! |
Since the errors reported by validator will be likely sent through JSON or printed in a log:
I would recommend to remove most of the end-lines:
instead of:
The text was updated successfully, but these errors were encountered: