* Change methodHandler element type to methodContext
Signed-off-by: ortyomka <iurin.art@gmail.com>
* Allow different param names in the smae path with different methods
Signed-off-by: ortyomka <iurin.art@gmail.com>
* Rename methodContext to routeMethod
Add paramsCount in each node for perfomance
Signed-off-by: ortyomka <iurin.art@gmail.com>
* Add backtracking to nearest path
Signed-off-by: ortyomka <iurin.art@gmail.com>
* Remove params from NotAllowed
Signed-off-by: ortyomka <iurin.art@gmail.com>
* when url ends with slash first param route is the match (fix#1804)
* router should check if method is suitable for matching route and if not then continue search in tree (fix#1808)
* Add tests for issue #1739
* Handle special trailing slash case only for a matching prefix
Only handle the special trailing slash case if the whole prefix matches to avoid matching
a wrong route for overlapping prefixes, e.g. /users/* for the path /users_prefix/ where
the route is only a partial prefix of the requested path.
Before this commit, all the node types were added to the same list of
children nodes. Taking in consideration that only one Param and Any type
of node could exist per node, two new node struct field were added to hold
the references to those kind of nodes.
This avoid the need to iterate through all the Static type nodes just to
find one Param or Any type node. Those iterations could be performed
multiple times in the same iteration of Router#Find.
Removing the route comments of the Router benchmark tests.
Updating the Router benchmarks tests to find the routes defined to each
particular benchmark. Before, all the benchmarks tried to find only the
GitHub API.
Adding new router benchmarks to measure when the Router try to find
routes that are not registered.
Before this fix, Router#Find panics or enters in an infinite loop when
the context params values were set to a number less than the max number
of params supported by the Router.
Fixed panic when Router#Find fails to find a route that could match a
Param route that only have children routes and no root route.
e.g
/create
/:id/edit
/:id/active
Finding /creates results in panic because the router tree node that
belongs to the param route :id don't have pnames on it. The childrens of
:id (:id/edit and :id/active) have the pnames properly set, but those
are not processed because /creates don't match on those paths.
* refs #1526: Add tests for trailing slash requests with nested any routes
* refs #1526: Handle specual router case with trailing slash for non-root any route
* refs #1526: Fix accidential lookup for any route without trailing slash in request
* Add test for issue #1509 for dynamic routes and multiple static routes with common prefix
* Fix#1509: routing conflict for dynamic routes and static route with common prefix
* Improve routing performance for static only route trees
* set parameter value in the pvalues slice
* update echo version
* update travis yml to fix failing build and add go modules support
* Add tests
* Update router_test.go
Co-authored-by: Vishal Rana <vr@labstack.com>
Currently a route in the form of `/foo/:id.json` means echo will detect
the parameter name `id.json` instead of the expected `id`. I think this
is rather counter-intuitive, as adding an extension to paths is a fairly
common use case.
With this change both a `/` and a `.` will be treated as the end of a
parameter name.
Benchmark before this change:
$ go test -bench .
[..]
goos: linux
goarch: amd64
pkg: github.com/labstack/echo
BenchmarkRouterStaticRoutes-4 100000 17743 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 33081 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 300000 5370 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 200000 9183 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo 8.565s
After this change:
goos: linux
goarch: amd64
pkg: github.com/labstack/echo
BenchmarkRouterStaticRoutes-4 100000 17699 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGitHubAPI-4 50000 32962 ns/op 1 B/op 0 allocs/op
BenchmarkRouterParseAPI-4 300000 5450 ns/op 0 B/op 0 allocs/op
BenchmarkRouterGooglePlusAPI-4 200000 9205 ns/op 0 B/op 0 allocs/op
PASS
ok github.com/labstack/echo 8.590s
Fixes#599