form icon indicating copy to clipboard operation
form copied to clipboard

Serialize composite []string with empty square brackets

Open Integralist opened this issue 4 years ago • 2 comments

👋🏻 I have an API that expects data to be sent like so:

services[]=A&services[]=B

How can I achieve this?

Currently the default behaviour appears to number each element within the slice.

I see there's a DelimitWith method but that doesn't quite achieve what I need (e.g. DelimitWith('|')):

services|0=A&services|1=B

Is there a custom unmarshal method I can define that might help encode the data how I need it?

Thanks!

Integralist avatar Sep 17 '21 18:09 Integralist

just use https://github.com/google/go-querystring

kokizzu avatar Jun 09 '22 13:06 kokizzu

That's exactly what I ended up doing 🙂

Integralist avatar Jun 09 '22 14:06 Integralist