GithubHelp home page GithubHelp logo

Comments (7)

deankarn avatar deankarn commented on August 15, 2024

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.

manucorporat avatar manucorporat commented on August 15, 2024

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.

deankarn avatar deankarn commented on August 15, 2024

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.

manucorporat avatar manucorporat commented on August 15, 2024

@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.

manucorporat avatar manucorporat commented on August 15, 2024

offtopic: I love the new v5 API. nice work!

from validator.

deankarn avatar deankarn commented on August 15, 2024

thanks @manucorporat

I'll take a look

from validator.

manucorporat avatar manucorporat commented on August 15, 2024

nice!

from validator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.