diff --git a/httpr.go b/httpr.go index 2a4d2bf..4558075 100644 --- a/httpr.go +++ b/httpr.go @@ -212,28 +212,25 @@ func (rr *Router) ServeStatic(path string, root http.FileSystem) error { // passed by a Handler() func. type subPath struct { r *Router - root string + base string } // Sub returns a sub-path with a root path, after that you can shorten patterns. // -// E.g. instead of writing each time "/api/something/other" create a -// sub-router with a root path "/api/something" and then pass just "/other" in -// a Handler() func of subPath struct. -func (rr *Router) Sub(root string) *subPath { - if root[len(root)-1] == '/' { - root = root[:len(root)-1] +func (rr *Router) Sub(base string) *subPath { + if base[len(base)-1] == '/' { + base = base[:len(base)-1] } return &subPath{ r: rr, - root: root, + base: base, } } // Handler attaches root path to a given pattern and pass it to a router. func (sp *subPath) Handler(method, pattern string, handler http.HandlerFunc) error { - return sp.r.Handler(method, sp.root+pattern, handler) + return sp.r.Handler(method, sp.base+pattern, handler) } // Param returns a URL parameter (that is set like `/a/b/:key/d`) with a key