summaryrefslogtreecommitdiff
path: root/mux.go
diff options
context:
space:
mode:
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)
+}