I have the following code which I have tried to use to send a post request where I want to upload a js.map file to bugsnag.
...
body := &bytes.Buffer{}
writer := multipart.NewWriter(body)
part, err := writer.CreateFormFile(filetype, filename)
if err != nil {
log.Fatal(err)
}
fmt.Printf("Sending %s to bugsnag", filename)
io.Copy(part, file)
writer.Close()
request, err := http.NewRequest("POST", bugsnagUrl, body)
if err != nil {
log.Fatal(err)
}
request.Header.Add("Content-Type", writer.FormDataContentType())
// This is where my problem seems to be, I can't add form values this way because the map is nil
request.Form.Add("apiKey", bugsnagToken)
request.Form.Add("minifiedUrl", fileurl)
request.Form.Add("sourceMap", filename)
request.Form.Add("overwrite", "true")
client := &http.Client{}
response, err := client.Do(request)
if err != nil {
log.Fatal(err)
}
defer response.Body.Close()
The above example gives the following error
panic: assignment to entry in nil map
goroutine 1 [running]: net/url.url.Values.Add(...)
I have been unable to find any examples on how to do this, I used the example on how to upload a file from this question to get this far.
I seem to be able to post the file but how can I post a file and also include post form values with my request?