Comments (7)
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
Email is required
Instead of
Field validation for "Email" failed on the "required" tag
from validator.
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?
see! there are many end-lines in the error message.
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")
}
from validator.
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
from validator.
@joeybloggs nice!
check out my work in progress, maybe we should join efforts (but for now... I am going to sleep ;) )
https://github.com/gin-gonic/validator/commit/474180a2dd22572102897e4db08c6fddbac5c767
gin-gonic/gin@784d734
from validator.
offtopic: I love the new v5 API. nice work!
from validator.
thanks @manucorporat
I'll take a look
from validator.
nice!
from validator.
Related Issues (20)
- Cron validator is not correct
- Can't validate both `keys` and the struct value of maps of structs
- StructPartial does not dive to slice of structs HOT 1
- Proposal: Support validator chaining
- Multiple validations at one time
- Bool to struct{} in iso codes
- Failing validation using the base64url tag
- SSN regex doesn't match the rest of the validation and is loose with formatting rules
- Add support for `errors.As`
- err.Translate(trans) only works if translator passed via param (go-playground/validator)
- Is is possible to check if an array is greater then 0 in required_if
- Is it possible to register custom validation function directly returning errors? HOT 1
- Support for mutually exclusive groups of validations chained with OR
- security: update mimetype dependency to new secure version
- Partial struct validation does not validate child structs HOT 1
- Validation failed url with required_without
- validator for IBAN HOT 4
- Missing FieldError.Field() and 'Key' in ValidationErrors Returned from Var() and ValidateMap()
- Github sponsorhip HOT 1
- Panic on max, min Validation Tag with struct Fields in Version v10.20.0 and above
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from validator.