title: how do i validate the body structure of rest api request in golang
body: <p>I am trying to ensure the body of a post request for example contains exact structure of the body and if not ahould throw an error</p>
  <p>for example i have the following function</p>
  <pre><code>func UpdatePassword(c *fiber.Ctx) error {
  
      type UpdatePasswordData struct {
          Password  string `json:&quot;password&quot; form:&quot;password&quot;`
          NewPassword string `json:&quot;new_password&quot; form:&quot;new_password&quot;`
          NewPasswordConfirm string `json:&quot;new_password_confirm&quot; form:&quot;new_password_confirm&quot;`
      }
      
      data := UpdatePasswordData{}
  
      if err := c.BodyParser(&amp;data); err != nil {
          return err
      }
  
      var user models.User
      
      if data.NewPassword != data.NewPasswordConfirm {
          c.Status(400)
          return c.JSON(fiber.Map{
              &quot;message&quot;: &quot;passwords do not match&quot;,
          })
      }
  
      email, _ := middlewares.GetUserEmail(c)
  
      newPassword := models.HashPassword(data.NewPassword)
  
      database.DB.Model(&amp;user).Select(&quot;Password&quot;).Where(&quot;email = ?&quot;, email).Updates(map[string]interface{}{&quot;Password&quot;: newPassword})
  
      return c.JSON(user)
  }
  </code></pre>
  <p>the POST request should be looking for body with this structure</p>
  <pre><code>{
      &quot;password&quot;: &quot;oldpassword&quot;,
      &quot;new_password&quot;: &quot;newpassword&quot;,
      &quot;new_password_confirm&quot;: &quot;newpassword&quot;,
  }
  </code></pre>
  <p>but currently this endpoint accepts body that does not have this exact structure. So how do i enforce the structure in the body of request, so that if structure does not match, i throw an error?</p>