traefik/pkg/middlewares/chain/chain.go

28 lines
724 B
Go
Raw Normal View History

2018-11-14 09:18:03 +00:00
package chain
import (
"context"
"net/http"
"github.com/containous/alice"
2019-08-03 01:58:23 +00:00
"github.com/containous/traefik/v2/pkg/config/dynamic"
2019-09-13 17:28:04 +00:00
"github.com/containous/traefik/v2/pkg/log"
2019-08-03 01:58:23 +00:00
"github.com/containous/traefik/v2/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) {
2019-09-13 17:28:04 +00:00
log.FromContext(middlewares.GetLoggerCtx(ctx, name, typeName)).Debug("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)
}