From 21660af7bef5e7a0e679fcbd8bee7352642b24f8 Mon Sep 17 00:00:00 2001 From: Eltrac Date: Thu, 27 Nov 2025 11:19:29 +0800 Subject: fix(router): `/path` and `/path/` were not the same route --- router.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/router.go b/router.go index 193d076..86d706a 100644 --- a/router.go +++ b/router.go @@ -19,13 +19,17 @@ func NewRouter() *Router { return &Router{} } +func (r *Router) splitPath(path string) []string { + return strings.Split(strings.Trim(path, "/"), "/") +} + func (r *Router) Add(method string, path string, h Handler) { - parts := strings.Split(path, "/") + parts := r.splitPath(path) r.routes = append(r.routes, route{method, parts, h}) } func (r *Router) Find(method string, path string) (Handler, map[string]string) { - parts := strings.Split(path, "/") + parts := r.splitPath(path) for _, rt := range r.routes { // match HTTP method -- cgit v1.2.3