I need to POST the following curl command using Go
curl -X POST http://localhost:8001/routes/route_name -F "name=function" -F "config.file[1]=@my_file.lua"
I have been looking into multipart file upload examples, but I can't wrap my head around how to create a post with a nested field name (config.file
is a config object with file as an array of strings) using CreateFormFile(key, val)
.
The problem I am having is according to the docs (https://pkg.go.dev/mime/multipart#Writer.WriteField) the WriteField API takes a field name and a value (path to file to post). I am not sure how to post a field name that is in a nested object e.g. CreateFormFile("config.file", filePath)
.
Anyone know how to convert the above curl command to Go using POST.