title: How can you bind a POST body to map?
body: <p>I've been using Gin's ShouldBind() method to bind form data to a struct:</p>
  
  <pre><code>type UpdateUserInfoContext struct {
      Country   string `json:"country"`
      EmailAddr string `json:"emailAddr"`
      LoginID   string `json:"loginID"`
      UserName  string `json:"username"`
  }
  
  func (h *handler) updateUserInfo(ctx *gin.Context) {
  
      var json UpdateUserInfoContext
  
      if err := ctx.ShouldBind(&amp;json); err != nil {
          ctx.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
          return
      }
  
      h.service.UpdateUserPassword(json)
  
      ctx.JSON(http.StatusOK, "success")
  
  }
  </code></pre>
  
  <p>But now I need to build a large, dynamic UPDATE SQL based on what is and isn't present in the body of a POST request. Since ShouldBind() binds to a struct I can't iterate over the values in the body without using reflection.  I figured an easier way would be to see if there's a method to bind the requests to a map instead of a struct.  There is the context method <code>PostFormMap(key string)</code>, however as far as I can tell from the example given here (<a href="https://github.com/gin-gonic/gin#another-example-query--post-form" rel="nofollow noreferrer">https://github.com/gin-gonic/gin#another-example-query--post-form</a>), this method requires the values correspond to to the argument key in the request body.  Does anyone have any experience doing this?  Thank you!</p>