I'm trying to make unit testing for my Go application that handles form data in multipart/form-data content type using gin (PostForm and PostFormArray) like
x, y := c.PostForm("x"), c.PostFormArray("y")
I have no problem on making a form field which have non-array value (PostForm) with mime/multipart library which Go provides like this
buf := new(bytes.Buffer)
w := multipart.NewWriter(buf)
x, _ := w.CreateFormField("x")
x.Write([]byte("This is x value"))
w.Close()
which PostForm handles perfectly, now I'm wondering if there is any way to send a multipart/form-data field with an array as its value like []string{"this is y 1", "this is y 2"} for it to work with gin's PostFormArray. Is it possible and how do I do it? Any help would be greatly appreciated. Thanks in advance!
y1, _ := w.CreateFormField("y")theny1.Write([]byte("this is y 1")), andy2, _ := w.CreateFormField("y")theny2.Write([]byte("this is y 2"))?