portal/api/middleware/util.go

16 lines
341 B
Go
Raw Normal View History

2024-01-19 22:11:16 +00:00
package middleware
import (
"go.sia.tech/jape"
)
2024-01-19 22:12:26 +00:00
type MiddlewareFunc func(jape.Handler) jape.Handler
func ApplyMiddlewares(handler jape.Handler, middlewares ...MiddlewareFunc) jape.Handler {
2024-01-19 22:11:16 +00:00
// Apply each middleware in reverse order
for i := len(middlewares) - 1; i >= 0; i-- {
handler = middlewares[i](handler)
}
return handler
}