Closed barthr closed 6 years ago
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?
Twirp services can only be mounted on the root path. See, the generated service router works on the req.URL.Path
https://github.com/twitchtv/twirp/blob/dff337b186d4ea1ada1d1e54ef422fdbcfa3113d/example/service.twirp.go#L156
it looks for an exact match, independently of where it was mounted. Maybe this is the issue?
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!
Right, github.com/gorilla/mux uses r.Handle
as an exact match, not a prefix match.
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 thehttp.Handler
interface and also theHandle
method for registring ahttp.Handler
with a specific path.