Any project that transform querystring in a map?

Anyone know any project that transforms the query strings into a map, something like rails params.

?pagination.page=23&pagination.quantity=30&filters.brand=dell&filters.color=red

Generates:

{pagination: { page: 23, quantity: 30 }, brand: 'dell', color: 'red' }

https://golang.org/pkg/net/url/#URL.Query

specifically, if you’re inside a http handler, request.URL.Query()

Not really, URL.Query() will return this:

{pagination.page: 23, pagination.quantity: 30, filters.brand: 'dell', filters.color: 'red' }

instead of this:

{pagination: { page: 23, quantity: 30 }, brand: 'dell', color: 'red' }

isn’t hard to implement this func, but, i thought had something ready to use :stuck_out_tongue:

Oh I see. You want it to interpolate name prefixes separated by dots as
representing distinct objects with the same name representing a single
object? You’re right, I don’t know of anything that does that by default.
Shouldn’t be hard to split the keys on dots and insert them into a
map[string]interface{} but yes it would require code.

Sorry,
– Charles

FWIW, I think a lib that would unmarshal it to a struct (not map) would be better

Shameless plug: http://mholt.github.io/binding/

(Library works, but I haven’t touched it in a while.)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.