I am working on a project using the fiber/v2
router, for a request mocking service. Now parameters passed via request body and query parameters are not an issue and handled easily. But here lies the problem with path parameters: Let's say we have a basic endpoint like http://host.org:port/
, I will denote this by "be". Now for a URL like
be/invoke/param1/param2
where the user sending request has the option to send just param1
or param1
and param2
both, parsing looks like a difficult task. There can be many types of cases and it is definitely hard to generalize in my opinion. It would be great if people could help with this case and then we maybe can generalize the problem.
Of course we need not look on cases like:
be/invoke/param1/details/param2
This becomes much harder :P
P.S. We are strictly trying to solve this problem in fiber because porting the entire thing to gin is not feasible, thanks.
I referred the Gin framework because they implement both Query and Path parameter parsing. But I was not very clear on how they were doing it and didn't find example for more dynamic use cases.
Edit 1: Thanks for the comment Cerise, the question is directed more towards detection of a passed parameter (The phrasing makes it look more generic :P ). Is there a way to detect a passed unnamed parameter? Or do I need to take the pattern of request while adding the service in my repository of service mocks?
Edit 2: I think an example will make this more clear:
I can get all the queyParams like
qParams := c.Queries()
Where c is of type *fiber.Ctx and Queries() returns a map of query and query value pairs.
I want to do something similar for path parameters such that:
pathParams := Parameters(c)
where Parameters() will return me all the path params(since c.Params() by definition requires the key I need to pick the value of)