-
Notifications
You must be signed in to change notification settings - Fork 5
Use dynamic route with URL parameters #94
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about providing a small interface to leverage routers libraries?
type RouteHandler interface {
KeyspaceRoute(pattern string) string
Keyspace(r *http.Request) string
}
type httpRouterHandler struct { }
func NewHttpRouterHandler() httpRouterHandler {
return httpRouterHandler{}
}
func (h httpRouterHandler) KeyspaceRoute(pattern string) string {
return path.Join(pattern, ":keyspace")
}
func (h httpRouterHandler) Keyspace(r *http.Request) string {
params := httprouter.ParamsFromContext(r.Context())
return params.ByName("keyspace")
}
Full patch: 1eaa7ca (updated)
My only concern is that it requires more code from endpoint route user pov. For cloud, if they decide to switch to mux it will involve implementing this interface vs changing a setting. |
That would also work with type gorillaMuxHandler struct { }
func NewHttpRouterHandler() gorillaMuxHandler {
return gorillaMuxHandler{}
}
func (h gorillaMuxHandler) KeyspaceRoute(pattern string) string {
return path.Join(pattern, "{keyspace}")
}
func (h gorillaMuxHandler) Keyspace(r *http.Request) string {
vars := mux.Vars(r)
return vars["keyspace"]
} |
It ends up being a very small amount of stateless code and using a regex doesn't leverage the router's capabilities so we end up double parsing the url. |
I think exposing less API surface for cloud integration and simple settings are a plus, even at the cost of being less extensible and parsing the url ourselves, but I don't have strong feelings about it. I'll rebase this and address the lock optimization. |
2f73c93
to
60ced89
Compare
Done! Feel free to push the |
Secret option C: Because we're not leveraging the URL templating in either router, meaning we don't need to have the syntax We know that keyspace is the last segment in the pattern: |
Interesting... I'm not sure I understand how routers would match the path without a router-based expression like |
Resolves #92 .
With this patch, a route with the pattern
/graphql/:keyspace
is always created and the keyspace is obtained from the url path.