summaryrefslogtreecommitdiff
path: root/mux.go
diff options
context:
space:
mode:
authorAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-31 02:05:36 +0300
committerAlexander Neonxp Kiryukhin <i@neonxp.ru>2024-08-31 02:05:36 +0300
commit5094ebf213243023c6325310b3f710a0974025dd (patch)
tree98b501b07271645f924b70af00bf8792d6062d65 /mux.go
parent376839b264c7f77b2540ad9f83bd8baf44063f17 (diff)
Обновление muxv0.0.1
Diffstat (limited to 'mux.go')
-rw-r--r--mux.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/mux.go b/mux.go
new file mode 100644
index 0000000..1631d10
--- /dev/null
+++ b/mux.go
@@ -0,0 +1,28 @@
+package mux
+
+import "net/http"
+
+type Mux struct {
+ http.ServeMux
+ middlewares []Middleware
+ groups map[string]*Mux
+}
+
+func New() *Mux {
+ return &Mux{
+ ServeMux: http.ServeMux{},
+ middlewares: []Middleware{},
+ groups: map[string]*Mux{},
+ }
+}
+
+func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ for path, g := range m.groups {
+ m.Handle(path, g)
+ }
+ h := http.Handler(&m.ServeMux)
+ for _, mw := range m.middlewares {
+ h = mw(h)
+ }
+ h.ServeHTTP(w, r)
+}