httprouter
httprouter copied to clipboard
How can I receive multiple parameters in GET request?
I'd like to handle an HTTP GET request, like this:
/search/projects?page=0&min=0&max=10000&ids=57,28,55,53,51,611,619,610,578,96,4,177
As far as I see in the docs only one parameter is mentioned in get requests. So I'm wondering how can I achieve a multi-parameter GET?
You should be able to get the query params like this off your request r
.
min := r.URL.Query().Get("min")
max := r.URL.Query().Get("max")
I think what you are asking about is httprouter.Params
. Say you have this route /api/users/:userId
you could access userId
in your handler as shown below.
func users(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
userId: = p.ByName("userid")
}
I made some changes to the project but waiting on approval to get them merged, in the meantime what you are asking can be done check it out here https://github.com/sainzg/httprouter/blob/main/params_test.go - TestMissingContextParams
这是来自QQ邮箱的假期自动回复邮件。 您好,我最近正在休假中,无法亲自回复您的邮件。我将在假期结束后,尽快给您回复。