go-siris / siris

DEPRECATED: The community driven fork of Iris. The fastest web framework for Golang!
Other
142 stars 16 forks source link

Multiple fields [GET params] #29

Closed everton-sales-branco closed 7 years ago

everton-sales-branco commented 7 years ago

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 commented 7 years ago

You can use a struct for it.

Von meinem iPhone gesendet

Am 06.07.2017 um 16:11 schrieb EvertonSalesBranco notifications@github.com:

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?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.

everton-sales-branco commented 7 years ago

@Dexus Is there any function to it?

Dexus commented 7 years ago

I mean yes but I have just no computer to look. I mean there is also an example or maybe it was on the iris website as long as it was available...

Von meinem iPhone gesendet

Am 06.07.2017 um 20:17 schrieb EvertonSalesBranco notifications@github.com:

@Dexus Is there some function to it?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

Allendar commented 7 years ago

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)
}
Dexus commented 7 years ago

Try this: https://github.com/google/go-querystring/issues/7#issuecomment-259792233

It's not yet for GET Params (Querystring) implemented if looked just into it. But we can do it.

Dexus commented 7 years ago

Or even better maybe: https://github.com/pasztorpisti/qs

Dexus commented 7 years ago

When you use ctx.Request.URL.Query() and qs or schema you don't need to build this crap wrapper...

everton-sales-branco commented 7 years ago

Ok, qs is the solution.

Dexus commented 7 years ago

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.