traefik/pkg/middlewares/chain/chain.go

27 lines
654 B
Go
Raw Normal View History

2018-11-14 09:18:03 +00:00
package chain
import (
"context"
"net/http"
"github.com/containous/alice"
"github.com/containous/traefik/pkg/config/dynamic"
2019-03-15 08:42:03 +00:00
"github.com/containous/traefik/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
}
// New creates a chain middleware
func New(ctx context.Context, next http.Handler, config dynamic.Chain, builder chainBuilder, name string) (http.Handler, error) {
2018-11-14 09:18:03 +00:00
middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")
middlewareChain := builder.BuildChain(ctx, config.Middlewares)
2018-11-14 09:18:03 +00:00
return middlewareChain.Then(next)
}