summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-30 01:16:23 +0300
committerAlexander NeonXP Kiryukhin <i@neonxp.ru>2024-07-30 01:16:23 +0300
commit376839b264c7f77b2540ad9f83bd8baf44063f17 (patch)
tree126dd0fb16710dec2ab1a8ceb5de400630af1876
parent623eaf165a4f248681acfec094f2f1ac1e0ff89f (diff)
Добавил SubMux Group
-rw-r--r--group.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/group.go b/group.go
new file mode 100644
index 0000000..ad8f82a
--- /dev/null
+++ b/group.go
@@ -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...)),
+ )
+}