diff options
| author | Eltrac <hi@guhub.cn> | 2025-11-27 11:19:29 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-11-27 11:19:29 +0800 |
| commit | 21660af7bef5e7a0e679fcbd8bee7352642b24f8 (patch) | |
| tree | 2ea68589c16fc4eca98c0e2efc3650fe8588c3e7 | |
| parent | c6f91b272056255edbacf0d81b75b5995febf175 (diff) | |
fix(router): `/path` and `/path/` were not the same route
| -rw-r--r-- | router.go | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -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 |
