Multiple fields [GET params]
everton-sales-branco opened this issue · comments
Hi guys,
To get values in a query of GET method, like:
"?searchPhrase[fields][]=name&searchPhrase[fields][]=registry&test=abc"
I did something like this:
ctx.Request.Form["searchPhrase[fields][]"][0] -> name
ctx.Request.Form["searchPhrase[fields][]"][1] -> registry
I think is a good idea do some wrapper to that, I right?
@Dexus Is there any function to it?
I never used it, but I think it was something like this:
type FormObject struct {
Username string `form:"username"`
Password string `form:"password"`
}
func yourRouteFunction(c context.Context) {
form := &FormObject{}
c.ReadForm(form)
}
Try this: google/go-querystring#7 (comment)
It's not yet for GET Params (Querystring) implemented if looked just into it. But we can do it.
Or even better maybe: https://github.com/pasztorpisti/qs
When you use ctx.Request.URL.Query() and qs or schema you don't need to build this crap wrapper...
Ok, qs is the solution.
Internal notice:
Add a new context function for get params to parse into a struct. Also add a shortcut function to get fields only for querystrings, because ctx.request.Form
(ctx.FormValue('namestring')
or ctx.FormValues()
) overwrite same name fields with post/put params.