Skip to content

Commit

Permalink
Create middleware.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Piszmog authored Apr 3, 2024
1 parent a186152 commit 7a6fac6
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions server/middleware/middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package middleware

import "net/http"

type Handler func(http.Handler) http.Handler

func Chain(handlers ...Handler) Handler {
if len(handlers) == 0 {
return defaultHandler
}

return func(next http.Handler) http.Handler {
for i := len(handlers) - 1; i >= 0; i-- {
next = handlers[i](next)
}
return next
}
}

func defaultHandler(next http.Handler) http.Handler {
return next
}

0 comments on commit 7a6fac6

Please sign in to comment.