summaryrefslogtreecommitdiff
path: root/group.go
diff options
context:
space:
mode:
Diffstat (limited to 'group.go')
-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...)),
+ )
+}