Skip to content

Map as query parameter #1106

Closed
Closed
@guzmo

Description

@guzmo

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])

Activity

picone

picone commented on Sep 12, 2017

@picone

You can try this

context.GetQueryArray("test")
tsirolnik

tsirolnik commented on Oct 19, 2017

@tsirolnik
Contributor

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

syssam

syssam commented on May 20, 2018

@syssam
Contributor

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

thinkerou

thinkerou commented on Jun 6, 2018

@thinkerou
Member

@guzmo please see #1383 thanks!

appleboy

appleboy commented on Aug 6, 2018

@appleboy
Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @appleboy@tsirolnik@thinkerou@picone@guzmo

        Issue actions

          Map as query parameter · Issue #1106 · gin-gonic/gin