feat(SimpleRouter): add SubPath function
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Use this router for graceful shutdown
|
||||
func (rg *RouteGroup) StartServer(addr string) *http.Server {
|
||||
server := &http.Server{
|
||||
Addr: addr,
|
||||
@@ -118,6 +117,17 @@ func (rg *RouteGroup) registerRoute(method string, path string, handler http.Han
|
||||
rg.mux.HandleFunc(fullPath, rg.applyMiddlewares(handler).ServeHTTP)
|
||||
}
|
||||
|
||||
func (rg *RouteGroup) SubPath(path string) *RouteGroup {
|
||||
rgc := &RouteGroup{
|
||||
mux: rg.mux,
|
||||
basePath: rg.basePath + path + "/",
|
||||
}
|
||||
middlewares := make([]Middleware, len(rg.middlewares))
|
||||
copy(middlewares, rg.middlewares)
|
||||
rgc.middlewares = middlewares
|
||||
return rgc
|
||||
}
|
||||
|
||||
func (rg *RouteGroup) HandleFunc(method string, path string, handler http.HandlerFunc) {
|
||||
rg.registerRoute(method, path, handler)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user