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 (
|
import (
|
||||||
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
"git.lumeweb.com/LumeWeb/portal/interfaces"
|
||||||
"github.com/julienschmidt/httprouter"
|
"github.com/julienschmidt/httprouter"
|
||||||
|
"go.sia.tech/jape"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type MiddlewareFunc func(jape.Handler) jape.Handler
|
||||||
|
|
||||||
func Init(router interfaces.APIRegistry) error {
|
func Init(router interfaces.APIRegistry) error {
|
||||||
router.Register("s5", NewS5())
|
router.Register("s5", NewS5())
|
||||||
return nil
|
return nil
|
||||||
|
@ -17,3 +20,10 @@ func registerProtocolSubdomain(portal interfaces.Portal, mux *httprouter.Router,
|
||||||
|
|
||||||
(*router)[name+"."+domain] = mux
|
(*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