title: Request body validation
body: <p>I'm using gin to handle requests, but I'm having trouble validating data in a request body, e.g.</p>
  
  <pre><code>type User struct {
      Username  string  `json:"username" binding:"required,min=1,max=16"`
      Name  string  `json:"name" binding:"required,min=1,max=16"`
      Password string `json:"password" binding:"required,min=1,max=16"`
  }
  
  func loginHandler(ctx *gin.Context) {
      var user User
      if err := ctx.ShouldBindJSON(&amp;user); err != nil {
          ctx.JSON(http.StatusBadRequest, gin.H{
              "error": err.Error(),
          })
  }
  </code></pre>
  
  <p>How can I handle values with whitespaces like <code>"  username "</code> or <code>" John   Doe "</code>? As far as I know it's not possible to use regex in gin's validator. 
  What are the best practices or patterns for request body validation in Golang? </p>