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

Get parameters through standard http.Handler #22

Closed
bodokaiser opened this issue Jul 18, 2014 · 2 comments
Closed

Get parameters through standard http.Handler #22

bodokaiser opened this issue Jul 18, 2014 · 2 comments

Comments

@bodokaiser
Copy link

Hello,

you write yourself that there is no efficient way to retrieve parameters without providing a third parameter.

I thought of four possible ways which we see partly in other routers:

  1. Save parameter in request.URL.Query() pat
  2. Save match with request and resolve it extra gorilla/mux
  3. Rerun route matcher on url to extract parameter.

The third one would require another extraction of the route parameter but as it is optional and does not require any extra cache layer I think it could be still efficient (if this is your main concern).

Best,
Bo

@julienschmidt
Copy link
Owner

  1. Also requires additional parsing (and allocations)
  2. Allocations + a synchronization hot spot
  3. Does the work twice

@bodokaiser
Copy link
Author

The last idea I have is using type casting on *url.URL as it is done with http.Flusher:

f, ok := w.(http.Flusher)

or with the url:

url, ok := request.URL.(httprouter.URL)

if ok {
    fmt.Printf("param: %s\n", url.Param("id"))
}

This could also be hidden somehow in a helper function:

id, err := httprouter.Param(r, "id")

What do you think?

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

No branches or pull requests

2 participants