diff options
author | tjpcc <tjp@ctrl-c.club> | 2023-09-17 19:57:50 -0600 |
---|---|---|
committer | tjpcc <tjp@ctrl-c.club> | 2023-09-17 19:57:50 -0600 |
commit | 210e4d038e4be64490be02d6777254cf42e12503 (patch) | |
tree | d48112b707668a84868f422f577f8cd3fad1235e | |
parent | 4a1764e9005ace0af1d694e62d87077f833abe9f (diff) |
allow mounted sub-routers to own the root path without a trailing slash
-rw-r--r-- | router.go | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -72,13 +72,16 @@ func (r Router) Match(request *Request) (Handler, map[string]string) { // mounted sub-router should have patterns which only include the portion of the path // after whatever was matched by the prefix pattern. // -// The root pattern ("/") in the sub-router will become a route which must end with a -// forward slash. +// The root pattern ("/") in the sub-router will become a route which may or may not +// end with a forward slash. func (r *Router) Mount(prefix string, subrouter *Router) { prefix = strings.TrimSuffix(prefix, "/") for _, subroute := range subrouter.tree.Routes() { r.Route(prefix+"/"+subroute.Pattern, subroute.Value) + if subroute.Pattern == "" { + r.Route(prefix, subroute.Value) + } } } |