Добавил SubMux Group

This commit is contained in:
Alexander NeonXP Kiryukhin 2024-07-30 01:16:23 +03:00
parent 623eaf165a
commit 376839b264
Signed by: NeonXP
GPG key ID: 35E33E1AB7776B39

18
group.go Normal file
View 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...)),
)
}