I am building a router layer for an API where I take the response and extract a parameter (in this case a service_code
, the name can vary - service_code
, serviceCode
, code
need to handle all) from the request body and pass it to the service that needs it. The data can be in raw json format application/json
, query params, path params or as form data multipart/form-data
. I am able to do it with the others but with form, when I pass the payload to the destination service I get the error multipart: NextPart: EOF
.
Here is how I am reading the data:
c.MultipartForm()
postForm := c.Request.PostForm
queryParams := c.Request.URL.Query()
route := c.Request.URL.Path
body, _ := ioutil.ReadAll(c.Request.Body)
serviceCode, destUrl, payload := getCityCode(queryParams, route, body, postForm)
Then I pass this payload to http.NewRequest
http.NewRequest(method, destUrl, strings.NewReader(payload))
At the destination when I read the data:
data := models.Data{}
err := c.Bind(&data); err != nil {
c.JSON(400, gin.H{"error": err.Error()})
return
}
The error is multipart: NextPart: EOF
. Can someone help please!