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
feat: support google custome verb #413
Conversation
{"/{userId}:init", "/{userId}"}, | ||
{"/{userId:init}", "/{userId:init}"}, | ||
{"/users/{id:init}:init", "/users/{id:init}"}, | ||
{"/users/{id}", "/users/{id}"}, |
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.
this will fail: "/init/users/{id:init}:init" , "/init/users/{id:init}"
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.
i added it to case, and run success, is something wrong?
testCase := []struct{
path string
expectedPath string
}{
{"/{userId}:init", "/{userId}"},
{"/{userId:init}", "/{userId:init}"},
{"/users/{id:init}:init", "/users/{id:init}"},
{"/users/{id}", "/users/{id}"},
{"/init/users/{id:init}:init" , "/init/users/{id:init}"},
}
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.
tbh, i did not execute this test. i should have said "will this fail?". I came up with this test because I saw "ReplaceAllString" in removeCustomVerb. And this case "/:init/users:init/" is probably not a valid path, right?
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.
emmm, it likes "/users/{id:init}:init", so i think the case is not necessary.
and replace regex is ":customVerb$", it will just replace last word.
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.
ok, good!
curly.go
Outdated
@@ -72,6 +72,15 @@ func (c CurlyRouter) matchesRouteByPathTokens(routeTokens, requestTokens []strin | |||
return false, 0, 0 | |||
} | |||
requestToken := requestTokens[i] | |||
if hasCustomVerb(routeToken){ |
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.
the hasCustomVerb is doing a regexp operation. this will affect performance. for this reason, I would like to introduce a field in the Router called CustomVerbEnabled with an default value of false.
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.
@emicklei, now it will calculate if a route has custom verb when build route
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.
so, we don't need the CustomVerbEnabled !
path_processor.go
Outdated
@@ -29,6 +29,11 @@ func (d defaultPathProcessor) ExtractParameters(r *Route, _ *WebService, urlPath | |||
} else { | |||
value = urlParts[i] | |||
} | |||
if hasCustomVerb(key) { |
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.
is here need to check CustomVerbEnabled? @emicklei
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.
yes, do you agree?
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.
yes, it should be checked
} | ||
|
||
// Initialize for Route | ||
func (r *Route) postBuild() { | ||
r.pathParts = tokenizePath(r.Path) | ||
r.hasCustomVerb = hasCustomVerb(r.Path) |
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.
nice!
to complete the PR, we should have an entry in the features list on the README refering to https://cloud.google.com/apis/design/custom_methods and a minimal example in the /examples folder. |
@emicklei , i have added a example (examples/restful-google-custom-method.go) and updated readme.md, |
// This example shows how to create a Route with google custom method | ||
// Requires the use of a CurlyRouter and path should end with the custom method | ||
// | ||
// GET http://localhost:8080/resource/some-resource-id:init |
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.
resource -> basepath
func main() { | ||
DefaultContainer.Router(CurlyRouter{}) | ||
ws := new(WebService) | ||
ws.Route(ws.GET("/basepath/{resourceId}:init").To(fromPathParam)) |
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.
i think it is good to add another Route to demonstrate that the verb is causing another function to be called.
so next to :init have :reset or some other verb you can think of.
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.
@emicklei , well, i have already fixed example
i think we are ready to merge |
ok, lets do it, and we can resolve #394 |
well module support was quite a challenge with subpackages not importing a version. I will have a look again. Would be better to separate that from this PR. |
@emicklei ok, i removed the |
yes, i understand. It will be one of the first changes next to do. |
good! and now we can merge it, right? |
support google custome verb
resolve this issue. #394