Добавил SubMux Group
This commit is contained in:
parent
623eaf165a
commit
376839b264
1 changed files with 18 additions and 0 deletions
18
group.go
Normal file
18
group.go
Normal file
|
@ -0,0 +1,18 @@
|
|||
package mux
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func Group(mux *http.ServeMux, prefix string, group func(sm *http.ServeMux), middlewares ...Middleware) {
|
||||
groupMux := http.NewServeMux()
|
||||
group(groupMux)
|
||||
if !strings.HasSuffix(prefix, "/") {
|
||||
prefix += "/"
|
||||
}
|
||||
mux.Handle(
|
||||
prefix,
|
||||
http.StripPrefix(strings.TrimSuffix(prefix, "/"), Use(groupMux, middlewares...)),
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue