Skip to content
New issue

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

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

Already on GitHub? # to your account

gorilla mux not working with twirp handler #54

Closed
barthr opened this issue Jan 24, 2018 · 4 comments
Closed

gorilla mux not working with twirp handler #54

barthr opened this issue Jan 24, 2018 · 4 comments

Comments

@barthr
Copy link

barthr commented Jan 24, 2018

I was trying twirp today to add some calls to an existing service which uses the gorilla mux (https://github.com/gorilla/mux). But the handler from twirp wasn't working with the mux from gorilla. Is this intentional or something we could support in the future?

The mux from gorilla implements the http.Handler interface and also the Handle method for registring a http.Handler with a specific path.

@spenczar
Copy link
Contributor

spenczar commented Jan 24, 2018

This should work without much trouble. Like so:

svc := example.NewHaberdasherServer(...)

r := mux.NewRouter()
r.PathPrefix(example.HaberdasherPathPrefix).Handler(svc)

Could you post the code that isn't working for you?

@marioizquierdo
Copy link
Contributor

marioizquierdo commented Jan 24, 2018

Twirp services can only be mounted on the root path. See, the generated service router works on the req.URL.Path

switch req.URL.Path {

it looks for an exact match, independently of where it was mounted. Maybe this is the issue?

@barthr
Copy link
Author

barthr commented Jan 24, 2018

Ahh I see. Didn't notice that, I was defining it like this:

svc := example.NewHaberdasherServer(...)

r := mux.NewRouter()
r.Handle(example.HaberdasherPathPrefix, svc)

Mental note, always mount it on the root path with PathPrefix Thanks!

@spenczar
Copy link
Contributor

Right, github.com/gorilla/mux uses r.Handle as an exact match, not a prefix match.

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

No branches or pull requests

3 participants