Renamed a root var to a more logically suitable name base.
This commit is contained in:
parent
d53622908b
commit
aba211f3ec
15
httpr.go
15
httpr.go
@ -212,28 +212,25 @@ func (rr *Router) ServeStatic(path string, root http.FileSystem) error {
|
|||||||
// passed by a Handler() func.
|
// passed by a Handler() func.
|
||||||
type subPath struct {
|
type subPath struct {
|
||||||
r *Router
|
r *Router
|
||||||
root string
|
base string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sub returns a sub-path with a root path, after that you can shorten patterns.
|
// 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
|
func (rr *Router) Sub(base string) *subPath {
|
||||||
// sub-router with a root path "/api/something" and then pass just "/other" in
|
if base[len(base)-1] == '/' {
|
||||||
// a Handler() func of subPath struct.
|
base = base[:len(base)-1]
|
||||||
func (rr *Router) Sub(root string) *subPath {
|
|
||||||
if root[len(root)-1] == '/' {
|
|
||||||
root = root[:len(root)-1]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &subPath{
|
return &subPath{
|
||||||
r: rr,
|
r: rr,
|
||||||
root: root,
|
base: base,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handler attaches root path to a given pattern and pass it to a router.
|
// 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 {
|
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
|
// Param returns a URL parameter (that is set like `/a/b/:key/d`) with a key
|
||||||
|
Loading…
Reference in New Issue
Block a user