Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I get all param variables? #1816

Closed
cw-20020752 opened this issue Mar 8, 2022 · 6 comments · Fixed by #1853
Closed

How can I get all param variables? #1816

cw-20020752 opened this issue Mar 8, 2022 · 6 comments · Fixed by #1853

Comments

@cw-20020752
Copy link

cw-20020752 commented Mar 8, 2022

For example, if my url is /test/:param1/test2/:param2
Isn't there a function that returns all path variables including param1 and param2 in middleware?
(like url.Query())

What I expect is this.
-->
url : test/1/test2/2
function returns: param1:1, param2:2

@welcome
Copy link

welcome bot commented Mar 8, 2022

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template! If you need help or want to chat with us, join us on Discord https://gofiber.io/discord

@ReneWerner87
Copy link
Member

we do not have such a method, since we assumed that if the route itself is defined, you know the parameters

you can still get the route from the context and there is a parameters node which contains all parameters in a slice

@ReneWerner87
Copy link
Member

@cw-20020752

@long2ice
Copy link

Current I do like this:

params := make(map[string][]string)
for _, param := range c.Route().Params {
	params[param] = append(params[param], c.Params(param))
}

@ReneWerner87
Copy link
Member

@long2ice perhaps a new method in context worth ?

@cw-20020752
Copy link
Author

Thanks for your kind replies!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants