Getting all URL query keys and values?

2,213 views
Skip to first unread message

Ralf Rottmann

unread,
Mar 31, 2014, 9:08:52 AM3/31/14
to golan...@googlegroups.com
How do I get all query string keys and values via Golang's http package? Assume I've got a URI like: http://localhost:8080?a=1&b=2

request.URI.Query()

seems to only return the first pair.

--

Kamil Kisiel

unread,
Mar 31, 2014, 9:28:24 AM3/31/14
to golan...@googlegroups.com
Assuming you mean req.URL.Query()... it does the right thing: http://play.golang.org/p/ivrCg2jxg-

Ralf Rottmann

unread,
Mar 31, 2014, 10:33:11 AM3/31/14
to golan...@googlegroups.com
Thanks! I can't get it working with http.Request in an http HandleFunc.

Here is my code snippet:

func debug(w http.ResponseWriter, r *http.Request) {
u, _ := url.Parse(r.URL.String())
queryParams := u.Query()
...



On Monday, March 31, 2014 3:08:52 PM UTC+2, Ralf Rottmann wrote:

Ralf Rottmann

unread,
Mar 31, 2014, 10:41:36 AM3/31/14
to golan...@googlegroups.com
My bad. curl doesn't seem to handle multiple query string parameters...


On Monday, March 31, 2014 3:08:52 PM UTC+2, Ralf Rottmann wrote:
Reply all
Reply to author
Forward
0 new messages