Commit graph

44 commits

Author SHA1 Message Date
James Raspass
756fcb8d63
Bump minimum Go to 1.24, use b.Loop() (#1164)
Go 1.27 is out now so we can bump our minimum Go to 1.24
2026-08-31 10:58:08 +02:00
Vojtech Vitek (golang.cz)
29164f023b
fix: don't drop handlers that collide with a Mount()/Route() pattern (#1148)
* fix: don't drop handlers that collide with a Mount()/Route() pattern

Mount() (and Route(), which is sugar for it) registers a synthetic
"stub" handler on its exact mount pattern to connect it to the
subrouter. node.routes() used that stub as a signal to hide the whole
node from Routes()/Walk() — but if a real handler was also registered
on that same pattern (e.g. r.Get("/bar", h) next to
r.Route("/bar", ...)), it got hidden too, even though the route is
perfectly routable.

routes() now compares each handler against the stub by identity
(sameHandler, using reflection since http.HandlerFunc isn't ==
comparable) and only hides the stub itself, keeping any real handler
that shares the node. The "*" slot is only filtered on leaf nodes,
since Walk() also reads Handlers["*"] to detect a *ChainHandler and
propagate With() middleware into a subrouter — that entry has to
survive even when it's the same value as the stub.

Fixes #830.

Also adds a regression test for #750 (middlewares registered on a
Group not reaching handlers on a Route() mounted inside it), which
turns out to already be fixed on master — this just locks it in.

* Trim comments in routes() to just the why

* Rename sameHandler to equalHandlers; narrow the reflect switch to Func

Chan, Pointer, and UnsafePointer are already == comparable in Go —
only Func, Map, and Slice aren't, and Map/Slice identity was never a
real case here (the stub is always http.HandlerFunc or *ChainHandler).

* Explain why Routes() reports /api/* and not /api/{id} in TestRoutesHidesMountStub

* Trim comment in TestRoutesHidesMountStub
2026-08-20 10:55:43 +02:00
Lukas Jenicek
903cff2596
Propagate inline middlewares across mounted subrouters (#1049)
* add tests to cover broken scenarios

* fix missing middlewares in Walk function
2026-02-12 12:31:51 +01:00
C H
bed8648a22
optimize sructs with memory alignment / padding (#596) 2021-03-07 07:09:40 -05:00
Masaya Watanabe
681ea79f56
Fix: validate empty path param (#567)
Thanks @matsuyoshi30
2020-12-24 12:28:05 -05:00
Joakim Hamrén
99ad97ff6f
Route recursive-search regexp patterns (#506) 2020-04-16 08:10:37 -04:00
Peter Kieltyka
cd12532e98 fixes #333, which adds additional check to ensure wildcard is used at end of a url pattern 2019-01-09 09:32:43 -05:00
Domen Ipavec
624e6e12e9 Fix: regex matching only part of parameter (#258)
* Add start and end to param regex

* Added test for regex match whole param
2017-09-07 09:24:55 -07:00
Peter Kieltyka
d132b31857 middleware.GetHead (#248)
Add Match(..) bool to chi.Routes, and add middleware.GetHead to automatically route missing head requests to GET handlers

* Put chi.Routes pointer on the route Context instead of having to pass to the middleware

* Rename FindHandler to Find, and add breaking test when searching subtrees

* Rename middleware to GetHead, and update Mux#Find method to search subroutes

* Update README, router at ~1000 LOC

* Redefine Routes#Find(..) http.Handler to Routes#Match(..) bool

* Update benchmarks

* Slightly adjust GetHead middleware to make it clearer
2017-08-31 21:51:08 -04:00
Peter Kieltyka
ba73ba0623 FindRoute now returns specific method handler along with endpoints map 2017-08-22 13:58:43 -04:00
Nic Pottier
df0b91fada Add support for using {} in regex paths (#245) 2017-08-17 12:09:07 -04:00
Peter Kieltyka
25354a53cc go vet and golint the project, release 3.1.5 2017-08-02 17:27:05 -04:00
Vojtech Vitek
524a020446 Implement router tree Walker, an analogy to filepath.Walk (#222)
* Implement router tree Walker, an analogy to filepath.Walk

func Walk(r Routes, walkFn WalkFunc) error
type WalkFunc func(method string, route string, handler http.Handler, middlewares ...func(http.Handler) http.Handler) error

* Move Walker to tree.go
2017-07-25 13:24:32 -04:00
Peter Kieltyka
7e6b856011 Flatten Context.URLParams data structure 2017-07-24 16:38:22 -04:00
Peter Kieltyka
a40fe4fc12 Add test case for mux mounts 2017-07-21 10:22:23 -04:00
Peter Kieltyka
49e7138cab organize routing patterns as endpoints with pattern, handler, paramKeys in the leaf nodes 2017-07-09 19:17:12 -04:00
Peter Kieltyka
25201e8a88 Export access to Context.URLParams 2017-07-08 18:12:46 -04:00
Niklas Janlert
4cbb5e2f2a Avoid matching parameters across path segments (#216)
Fixes #215
2017-06-28 10:30:38 -04:00
Peter Kieltyka
02e6bbdfd1 v3.0.0 release 2017-06-21 10:43:59 -04:00
Peter Kieltyka
8f717baab4 v3 beta 1 2017-06-21 10:43:59 -04:00
Peter Kieltyka
34af882aa1 Record routing patterns throughout a request lifecycle 2016-07-22 11:34:02 -04:00
Peter Kieltyka
e10a47f9d4 Refinements 2016-07-21 22:30:07 -04:00
Peter Kieltyka
853f9c7806 Flatten tree, node and edges structures 2016-07-15 15:51:30 -04:00
Peter Kieltyka
c54b122dfe Refactor subrouters to build into a single tree 2016-07-11 07:28:48 -06:00
Peter Kieltyka
c12bec07f7 Remove parent context from constructors 2016-07-04 15:27:57 -04:00
Peter Kieltyka
6c38bd10bf Rename old-Route to Group and old-Group to Inline 2016-06-20 16:44:29 -04:00
Peter Kieltyka
9c87d91877 chi v2 first pass 2016-04-10 21:02:45 -04:00
Peter Kieltyka
f8b6dfe1ef Routing context improvements 2016-04-02 08:45:37 -04:00
Peter Kieltyka
520d4e05d3 Reuse root context in a sync pool to reduce GC: zero-alloc routing 2016-03-30 09:48:24 -04:00
Peter Kieltyka
ed5fa44b33 Improve subrouter traversal 2015-11-10 16:28:16 -05:00
Peter Kieltyka
e52df60c92 Minor changes to reuse variables 2015-11-06 15:03:01 -05:00
Peter Kieltyka
fffe601cb0 Refinements, tests and performance 2015-11-05 15:54:30 -05:00
Peter Kieltyka
522c0ce2d6 Expand the rest example 2015-10-28 17:49:10 -04:00
Peter Kieltyka
928913f54b Cleanup 2015-10-23 16:43:58 -04:00
Peter Kieltyka
caaa5eebe3 Subrouters, groups and inline middlewares 2015-10-22 15:55:39 -04:00
Peter Kieltyka
1123f01030 Add chainedHandler method to return middleware-chained end handler 2015-10-21 17:16:44 -04:00
Peter Kieltyka
dc8ebd1eb4 Support multiple HTTP methods, as well Handle() 2015-10-21 15:36:42 -04:00
Peter Kieltyka
4c747ca9f2 More mux tests, tree working well 2015-10-21 13:13:47 -04:00
Peter Kieltyka
c9a4b9a2c0 tree.Find calls on node.find 2015-10-20 13:35:31 -04:00
Peter Kieltyka
12bd6cec31 Catchall, tests 2015-10-19 15:50:27 -04:00
Peter Kieltyka
b9e01bcfb8 Move ctxhttp.Handler interface to chi, until there is standard approach 2015-10-16 13:44:16 -04:00
Peter Kieltyka
a826895b25 Clean up 2015-10-16 13:15:23 -04:00
Peter Kieltyka
24f8ac575c Clean up 2015-10-16 13:01:15 -04:00
Peter Kieltyka
f6e1f9da2f Init 2015-10-15 16:50:30 -04:00