How to match /{suffix...} in go-zero?
Can you describe it in more detail?
Can you describe it in more detail?
Issue Description
I am currently developing a gateway application that requires dynamic routing based on the suffix of the URL path. I am considering migrating our existing system to the go-zero framework to leverage its built-in features such as load balancing and distributed tracing. However, I’ve encountered a limitation in the go-zero routing system that may impede this migration.
Expected Behavior
I would like to confirm whether the go-zero routing system supports a pattern that allows for wildcard suffix matching, similar to /service/{suffix...}. This pattern should match any request path that starts with /service/ and is followed by any suffix. The gateway should be capable of capturing the entire suffix and routing it to the appropriate downstream service.
Use Case
The gateway should be able to route requests of a project to different module and API versions based on the suffix. For example, /awesome/api/v1/resource/... would direct requests to module-api, version-1 of the project-awesome. The gateway is intended to aggregate multiple microservices behind a single endpoint, with the suffix determining which specific service the request should be routed to, and apply queuing, lots of monitoring and functions.
func TestSearchTreeMatch(t *testing.T) { tree := search.NewTree() handler := func() { print("match!") } err := tree.Add("/a/:path", handler) if err != nil { t.Error(err) } res, matched := tree.Search("/a/b") if !matched { t.Error("not matched /a/b") } assert.Equal(t, res.Params["path"], "b") res, matched = tree.Search("/a/c/d/e") // 不能匹配 can not match if !matched { t.Error("not matched /a/c/d/e") } assert.Equal(t, res.Params["path"], "c/d/e") res, matched = tree.Search("/a") if matched { t.Error("matched /a") } else { t.Log("not matched /a") } res, matched = tree.Search("/a/") if matched { t.Log("matched /a/") } res, matched = tree.Search("/a/c?q=1") if !matched { t.Error("not matched /a/c?q=1") } assert.Equal(t, res.Params["path"], "c?q=1") }
here is it
This issue is stale because it has been open for 30 days with no activity.