summaryrefslogtreecommitdiff
path: root/router.go
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-11-28 23:13:23 +0800
committerEltrac <hi@guhub.cn>2025-11-28 23:13:23 +0800
commit3f53ba50f2e562b5a2bc97442266b5e7acd585eb (patch)
treeab29b0db71bb1661af0502b3b3442fb0f84a0590 /router.go
parentaccb1bae86a3547f16dcc448f92ec73a493dfd85 (diff)
feat(router, context)!: support query string also move path split logic to
parser.go
Diffstat (limited to 'router.go')
-rw-r--r--router.go15
1 files changed, 6 insertions, 9 deletions
diff --git a/router.go b/router.go
index 961230a..d17d132 100644
--- a/router.go
+++ b/router.go
@@ -8,17 +8,14 @@ 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 := r.splitPath(path)
+ parts, _ := ParsePath(path)
r.routes = append(r.routes, Route{method, parts, h})
}
-func (r *Router) Find(method string, path string) (Handler, map[string]string) {
- parts := r.splitPath(path)
+func (r *Router) Find(method string, path string) (
+ handler Handler, params map[string]string, query map[string]string) {
+ parts, query := ParsePath(path)
for _, rt := range r.routes {
// match HTTP method
@@ -49,8 +46,8 @@ func (r *Router) Find(method string, path string) (Handler, map[string]string) {
}
}
if matched {
- return rt.handler, params
+ return rt.handler, params, query
}
}
- return nil, nil
+ return nil, nil, nil
}