github.com/cozy/cozy-stack@v0.0.0-20240603063001-31110fa4cae1/web/middlewares/middlewares.go (about)

     1  package middlewares
     2  
     3  import (
     4  	"github.com/labstack/echo/v4"
     5  )
     6  
     7  // Compose can be used to compose a list of middlewares together with a main
     8  // handler function. It returns a new handler that should be the composition of
     9  // all the middlwares with the initial handler.
    10  func Compose(handler echo.HandlerFunc, mws ...echo.MiddlewareFunc) echo.HandlerFunc {
    11  	for i := len(mws) - 1; i >= 0; i-- {
    12  		handler = mws[i](handler)
    13  	}
    14  	return handler
    15  }