Gin: Map as query parameter

Created on 11 Sep 2017  路  5Comments  路  Source: gin-gonic/gin

Is Map as query parameter supported? And if it is how to use it? I tried with:

localhost:8080?test[asd]=asd&test[dsa]=dsa

and the code

queries := c.Request.URL.Query()
// Doesn't work
log.Println(queries["test"])
// Gets the variable but not how I want it.
log.Println(queries["test[asd]"][0])
question

Most helpful comment

Was just about to post an issue regarding this subject

@picone GetQueryArray returns an array where @guzmo request is for a map, e.g -

a[]=1&a[]=2&a[]=3

Would fit for GetQueryArray

but

a[foo]=1&a[bar]=2

Would need a map as the result is the following map -

map[string]int{
    "foo": 1,
     "bar":2,
}

I couldn't find an existing solution for this in Gin

All 5 comments

You can try this

context.GetQueryArray("test")

Was just about to post an issue regarding this subject

@picone GetQueryArray returns an array where @guzmo request is for a map, e.g -

a[]=1&a[]=2&a[]=3

Would fit for GetQueryArray

but

a[foo]=1&a[bar]=2

Would need a map as the result is the following map -

map[string]int{
    "foo": 1,
     "bar":2,
}

I couldn't find an existing solution for this in Gin

Any one know this solution?
I also have this problem on Post Form

@guzmo please see #1383 thanks!

Please try the latest version and see the document https://github.com/gin-gonic/gin#map-as-querystring-or-postform-parameters

Was this page helpful?
0 / 5 - 0 ratings