feat: create ApplyMiddlewares helper
This commit is contained in:
parent
e9db71f3b8
commit
26c28db1f2
10
api/api.go
10
api/api.go
|
@ -3,8 +3,11 @@ package api
|
|||
import (
|
||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"go.sia.tech/jape"
|
||||
)
|
||||
|
||||
type MiddlewareFunc func(jape.Handler) jape.Handler
|
||||
|
||||
func Init(router interfaces.APIRegistry) error {
|
||||
router.Register("s5", NewS5())
|
||||
return nil
|
||||
|
@ -17,3 +20,10 @@ func registerProtocolSubdomain(portal interfaces.Portal, mux *httprouter.Router,
|
|||
|
||||
(*router)[name+"."+domain] = mux
|
||||
}
|
||||
func ApplyMiddlewares(handler jape.Handler, middlewares ...MiddlewareFunc) jape.Handler {
|
||||
// Apply each middleware in reverse order
|
||||
for i := len(middlewares) - 1; i >= 0; i-- {
|
||||
handler = middlewares[i](handler)
|
||||
}
|
||||
return handler
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue