2018-11-14 09:18:03 +00:00
|
|
|
package chain
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/containous/alice"
|
2020-09-16 13:46:04 +00:00
|
|
|
"github.com/traefik/traefik/v2/pkg/config/dynamic"
|
|
|
|
"github.com/traefik/traefik/v2/pkg/middlewares"
|
2018-11-14 09:18:03 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
typeName = "Chain"
|
|
|
|
)
|
|
|
|
|
|
|
|
type chainBuilder interface {
|
2019-01-15 13:28:04 +00:00
|
|
|
BuildChain(ctx context.Context, middlewares []string) *alice.Chain
|
2018-11-14 09:18:03 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 10:06:07 +00:00
|
|
|
// New creates a chain middleware.
|
2019-07-10 07:26:04 +00:00
|
|
|
func New(ctx context.Context, next http.Handler, config dynamic.Chain, builder chainBuilder, name string) (http.Handler, error) {
|
2022-11-21 17:36:05 +00:00
|
|
|
middlewares.GetLogger(ctx, name, typeName).Debug().Msg("Creating middleware")
|
2018-11-14 09:18:03 +00:00
|
|
|
|
2019-01-15 13:28:04 +00:00
|
|
|
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
|
2018-11-14 09:18:03 +00:00
|
|
|
return middlewareChain.Then(next)
|
|
|
|
}
|