title: How to validate data from a middleware go-gin
body: <p>Trying to learn golang, and I am lost on working with the <code>context.Request.Body</code> and its <code>struct</code> in a validation middleware</p>
  <p>briefly how do they connect to each other, thanks in advance for your help</p>
  <p>My middleware</p>
  <pre><code>package validations
  
  import (
      &quot;github.com/bihire/ikaze_server_app/entity&quot;
      &quot;net/http&quot;
      &quot;github.com/gin-gonic/gin&quot;
      &quot;github.com/go-playground/validator/v10&quot;
  )
  
  
  func SignupValidator(c *gin.Context) {
      // user := c.Request.Body
      var user entity.User
      validate := validator.New()
      if err := validate.Struct(&amp;user); err != nil {
          c.JSON(http.StatusBadRequest, gin.H{
              &quot;error&quot;: err.Error(),
          })
      }
  
  }
  </code></pre>
  <p>My struct</p>
  <pre><code>package entity
  
  type User struct {
      Username         string `json:&quot;username&quot; validate:&quot;required&quot;`
      Email            string `json:&quot;email&quot;  validate:&quot;email&quot;`
      Password         string `json:&quot;password&quot; validate:&quot;min=8,max=32,alphanum&quot;`
      ConfirmPassword  string `json:&quot;confirm_password&quot; validate:&quot;eqfield=Password,required&quot;`
  }
  </code></pre>
  <p>returned response error</p>
  <pre><code>{
      &quot;error&quot;: &quot;Key: 'User.Username' Error:Field validation for 'Username' failed on the 'required' tag\nKey: 'User.Email' Error:Field validation for 'Email' failed on the 'email' tag\nKey: 'User.Password' Error:Field validation for 'Password' failed on the 'min' tag\nKey: 'User.ConfirmPassword' Error:Field validation for 'ConfirmPassword' failed on the 'required' tag&quot;
  }{
      &quot;username&quot;: &quot;bihire&quot;,
      &quot;email&quot;: &quot;hgh@gmail.com&quot;,
      &quot;password&quot;: &quot;password&quot;,
      &quot;confirm_password&quot;: &quot;password&quot;
  }
  </code></pre>
  <p>router with middleware</p>
  <pre><code>auth.POST(&quot;login&quot;, gin.Logger(), validations.SignupValidator, func(ctx *gin.Context) {
              ctx.JSON(200, videoController.Save(ctx))
          })
  </code></pre>