For match any routes configured on multiple levels the wrong route seems to be chosen.
It is expected that if a route is not found, that the nearest (longest matching) match any route is chosen.
For the following defined routes
/api/user
/api/*
/*
it would be expected for any request under /api that can not be resolved to return the match any /api/* route, even those under /api/user/something.
This is currently handled for static only routes that way.
A PR will be opened to resolve this issue (probably alongside with #1406).
The route /api/* will be chosen
A not found is returned for /api/user/notexists
Run example below.
package main
import (
"net/http"
"github.com/labstack/echo/v4"
)
func main() {
// Echo instance
e := echo.New()
// Routes
e.GET("/admin", func(c echo.Context) error { return c.String(http.StatusOK, "admin") })
e.GET("/api/help", func(c echo.Context) error { return c.String(http.StatusOK, "api help") })
e.GET("/api/*", func(c echo.Context) error { return c.String(http.StatusOK, "api any") })
e.GET("/*", func(c echo.Context) error { return c.String(http.StatusOK, "root any") })
// Start server
e.Logger.Fatal(e.Start(":1323"))
}
Tested with v4.1.10
Here are some the benchmarks observed on my system.
Before (current master b129098):
BenchmarkRouterStaticRoutes-4 100000 21359 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 38609 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 200000 6683 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 100000 11278 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo/v4 7.348s
Success: Benchmarks passed.
With this PR:
BenchmarkRouterStaticRoutes-4 100000 17465 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 33817 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 200000 6578 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 200000 10046 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo/v4 7.470s
Success: Benchmarks passed.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
There seem to be no interest so far in fixing the router for the wrong any matches...
This is probably considered a corner case, so I guess we have to keep using our fork for now.
Feedback would be welcome though.
Looks like this project has been abandoned
The PR #1413 for this issue went stale and has been auto-closed by the bot without any comments or feedback.
I really hope this project is not abandoned as it is a really nice web framework and we'd love to switch back from our fork with the router fixes to the main project.
Comments for this issue or PR #1413 would be greatly appreciated.
@vishr Please merge this. We need this ASAP
@vishr Life Saver! Thanks :)
Consider getting more people to help you out. I for one would love to be a maintainer :)
@asahasrabuddhe I am planning to form a core team to maintain the project, will keep you in mind.
@vishr Thanks for merging!
We are using echo in most of our internal web service projects, so we might step up to as contributer/maintainer if needed (with focus on router and proxy middleware for now).