PathParams not a method on router

This commit is contained in:
2020-12-09 22:44:50 -08:00
parent df7e3ccc03
commit 3e7625bbeb

View File

@ -112,14 +112,6 @@ func (r *Router) AddRoute(method string, path string, callback http.HandlerFunc)
return
}
// PathParams takes a path and returns the values for any path parameters
// in the path.
func (r *Router) PathParams(req *http.Request) (params map[string]string) {
params = req.Context().Value(paramKey).(map[string]string)
return
}
// handler returns the handler to use for the given request, consulting r.Method, r.URL.Path. It
// always returns a non-nil handler.
//
@ -161,6 +153,14 @@ func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
return
}
// PathParams takes a path and returns the values for any path parameters
// in the path.
func PathParams(req *http.Request) (params map[string]string) {
params = req.Context().Value(paramKey).(map[string]string)
return
}
// addSegment create a new segment either as a child or as a parameter depending on whether the key
// qualifies as a parameter. A pointer to the created segment is then returned.
func addSegment(curr *segment, key string) (seg *segment) {