You've already forked golang-saas-starter-kit
mirror of
https://github.com/raseels-repos/golang-saas-starter-kit.git
synced 2025-06-15 00:15:15 +02:00
Imported github.com/ardanlabs/service as base example project
This commit is contained in:
24
example-project/internal/platform/web/middleware.go
Normal file
24
example-project/internal/platform/web/middleware.go
Normal file
@ -0,0 +1,24 @@
|
||||
package web
|
||||
|
||||
// Middleware is a function designed to run some code before and/or after
|
||||
// another Handler. It is designed to remove boilerplate or other concerns not
|
||||
// direct to any given Handler.
|
||||
type Middleware func(Handler) Handler
|
||||
|
||||
// wrapMiddleware creates a new handler by wrapping middleware around a final
|
||||
// handler. The middlewares' Handlers will be executed by requests in the order
|
||||
// they are provided.
|
||||
func wrapMiddleware(mw []Middleware, handler Handler) Handler {
|
||||
|
||||
// Loop backwards through the middleware invoking each one. Replace the
|
||||
// handler with the new wrapped handler. Looping backwards ensures that the
|
||||
// first middleware of the slice is the first to be executed by requests.
|
||||
for i := len(mw) - 1; i >= 0; i-- {
|
||||
h := mw[i]
|
||||
if h != nil {
|
||||
handler = h(handler)
|
||||
}
|
||||
}
|
||||
|
||||
return handler
|
||||
}
|
Reference in New Issue
Block a user