在fasthttprouter中将参数定义为参数请求而不是端点url

I am using golang´s fasthttprouter and have followed the examples and defined a router like this:

router.GET("/customer/account/detail/:accountId", myHandler.customerAccountDetailHandler)

Then I call to my service as http://locahost:9296/customer/account/detail/2

But I realised that I do not want to have the parameters as part of the endpoint , I rather prefer to use normal parameters by calling my service like this:

http://locahost:9296/customer/account/detail?accountId=2&sort=1

Is it possible to be done with fasthttprouter? How?

Thanks in advance J

The query parameter should be accessible from the request context. You should have a handler that takes a *fasthttp.RequestCtx argument. This RequestCtx can access the URI and the query params on that URI. That should look something like this:

ctx.URI().QueryArgs().Peek("accountId")

You'll have to update your handler to use this query parameter instead of the route param you were previously using. The same would also apply for the sort param.

Also, your router would have to be updated to route /customer/account/detail to your updated handler (i.e. you'll want to remove /:accountId from your route).

Your questions is similar to this one:
Get a request parameter key-value in fasthttp

You can retrieve the parameters of the request in this way:

token = string(ctx.FormValue("token"))

Have a look at my complete response here

https://stackoverflow.com/a/57740178/9361998

Documentation: https://godoc.org/github.com/valyala/fasthttp#RequestCtx.FormValue