traefik/pkg/middlewares/chain/chain.go

27 lines
661 B
Go
Raw Normal View History

2018-11-14 09:18:03 +00:00
package chain
import (
"context"
"net/http"
"github.com/containous/alice"
2023-02-03 14:24:05 +00:00
"github.com/traefik/traefik/v3/pkg/config/dynamic"
"github.com/traefik/traefik/v3/pkg/middlewares"
2018-11-14 09:18:03 +00:00
)
const (
typeName = "Chain"
)
type chainBuilder interface {
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.
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
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
2018-11-14 09:18:03 +00:00
return middlewareChain.Then(next)
}