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

Wildcard parameter name #46

Closed
antoooon opened this issue Nov 1, 2016 · 4 comments
Closed

Wildcard parameter name #46

antoooon opened this issue Nov 1, 2016 · 4 comments

Comments

@antoooon
Copy link

antoooon commented Nov 1, 2016

When adding a wildcard parameter (i.e. *param instead of :param), the parameter name will be "_name" instead of the parameter name given in the pattern.

@husobee
Copy link
Owner

husobee commented Nov 1, 2016

I guess the use case I was going for with the wildcard support was more like this:

    router := vestigo.NewRouter()
    router.Get("/static/*", http.StripPrefix("/static/", http.FileServer(http.Dir("/static")))

Where we have a "match all after the *" situation. I am worried about confusion adding parameter names to the wildcard, because then we would have confusing situations like this:

    router := vestigo.NewRouter()
    router.Get("/*wildcardparam1/foo", handler)

This becomes confusing for two reasons, should the wildcard act like a : param, or should the lookup for the matched portion of the route end up like something/foo or just something given the input url /something/foo?

I feel like wildcard parameters need only to be used to match to the end of URL, and if you need to access that wildcard parameter you can get it by means of vestigo.Param(req, "_name") or by performing a strip prefix handler.

If we could make named wildcard parameters less confusing, I would be up for adding support for it, but I feel like it will become confusing.

@antoooon
Copy link
Author

antoooon commented Nov 1, 2016

Thanks for your answer.

Indeed, wildcards only makes sense at the end of a pattern.
But it's nice to fetch the matched string just like I do with other parameters.
I had to read the source just to find out the magic parameter name "_name".

I guess "_name" is fine, as long as it's documented. I just stumbled over this when switching to vestigo from httprouter, which does save the wildcard parameter by the name given after "*".

@husobee
Copy link
Owner

husobee commented Nov 1, 2016

@antoooon: I can appreciate that. I am going to tag this as documentation, and will add a note to the readme about this. Will that be okay?

husobee added a commit that referenced this issue Jan 11, 2017
@husobee
Copy link
Owner

husobee commented Jan 11, 2017

documented in readme and merged. closing.

@husobee husobee closed this as completed Jan 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants