summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-12-03 15:21:07 +0800
committerEltrac <hi@guhub.cn>2025-12-03 15:21:07 +0800
commit2ac34a23542c7c66427e7ca9bd33d14ba03c0dd7 (patch)
tree934aa31c0ce6b0651b5f536732fe28ecc4662610
parent0358a87a409272cda621efcfa14e4231e9732fe4 (diff)
doc: write doc comments for Router
-rw-r--r--router.go8
1 files changed, 8 insertions, 0 deletions
diff --git a/router.go b/router.go
index d17d132..c5e8933 100644
--- a/router.go
+++ b/router.go
@@ -8,11 +8,19 @@ func NewRouter() *Router {
return &Router{}
}
+// Router.Add adds a route with specified method, path and handler
+// it splits path into segments for matching
func (r *Router) Add(method string, path string, h Handler) {
parts, _ := ParsePath(path)
r.routes = append(r.routes, Route{method, parts, h})
}
+// Router.Find finds route with same HTTP method and path
+// returns the handler, parameters and query
+//
+// handler is a function that wraps Context
+// params is a map of parameters from dynamic routing
+// query is a map of query parameters from URL
func (r *Router) Find(method string, path string) (
handler Handler, params map[string]string, query map[string]string) {
parts, query := ParsePath(path)