2019-11-14 15:40:05 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2021-09-15 08:36:14 +00:00
|
|
|
"github.com/gorilla/mux"
|
2023-02-03 14:24:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/api"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/api/dashboard"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/config/runtime"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/config/static"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/metrics"
|
|
|
|
"github.com/traefik/traefik/v3/pkg/safe"
|
2024-01-30 15:28:05 +00:00
|
|
|
"github.com/traefik/traefik/v3/pkg/server/middleware"
|
2019-11-14 15:40:05 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// ManagerFactory a factory of service manager.
|
|
|
|
type ManagerFactory struct {
|
2024-01-30 15:28:05 +00:00
|
|
|
observabilityMgr *middleware.ObservabilityMgr
|
2019-11-14 15:40:05 +00:00
|
|
|
|
2024-09-26 09:00:05 +00:00
|
|
|
transportManager *TransportManager
|
|
|
|
proxyBuilder ProxyBuilder
|
2019-11-14 15:40:05 +00:00
|
|
|
|
|
|
|
api func(configuration *runtime.Configuration) http.Handler
|
|
|
|
restHandler http.Handler
|
|
|
|
dashboardHandler http.Handler
|
|
|
|
metricsHandler http.Handler
|
|
|
|
pingHandler http.Handler
|
2020-10-29 14:40:04 +00:00
|
|
|
acmeHTTPHandler http.Handler
|
2019-11-14 15:40:05 +00:00
|
|
|
|
|
|
|
routinesPool *safe.Pool
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewManagerFactory creates a new ManagerFactory.
|
2024-09-26 09:00:05 +00:00
|
|
|
func NewManagerFactory(staticConfiguration static.Configuration, routinesPool *safe.Pool, observabilityMgr *middleware.ObservabilityMgr, transportManager *TransportManager, proxyBuilder ProxyBuilder, acmeHTTPHandler http.Handler) *ManagerFactory {
|
2019-11-14 15:40:05 +00:00
|
|
|
factory := &ManagerFactory{
|
2024-09-26 09:00:05 +00:00
|
|
|
observabilityMgr: observabilityMgr,
|
|
|
|
routinesPool: routinesPool,
|
|
|
|
transportManager: transportManager,
|
|
|
|
proxyBuilder: proxyBuilder,
|
|
|
|
acmeHTTPHandler: acmeHTTPHandler,
|
2019-11-14 15:40:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if staticConfiguration.API != nil {
|
2021-09-15 08:36:14 +00:00
|
|
|
apiRouterBuilder := api.NewBuilder(staticConfiguration)
|
2019-11-14 15:40:05 +00:00
|
|
|
|
|
|
|
if staticConfiguration.API.Dashboard {
|
2021-09-15 08:36:14 +00:00
|
|
|
factory.dashboardHandler = dashboard.Handler{}
|
|
|
|
factory.api = func(configuration *runtime.Configuration) http.Handler {
|
|
|
|
router := apiRouterBuilder(configuration).(*mux.Router)
|
|
|
|
dashboard.Append(router, nil)
|
|
|
|
return router
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
factory.api = apiRouterBuilder
|
2019-11-14 15:40:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if staticConfiguration.Providers != nil && staticConfiguration.Providers.Rest != nil {
|
|
|
|
factory.restHandler = staticConfiguration.Providers.Rest.CreateRouter()
|
|
|
|
}
|
|
|
|
|
|
|
|
if staticConfiguration.Metrics != nil && staticConfiguration.Metrics.Prometheus != nil {
|
|
|
|
factory.metricsHandler = metrics.PrometheusHandler()
|
|
|
|
}
|
|
|
|
|
2020-02-11 15:06:06 +00:00
|
|
|
// This check is necessary because even when staticConfiguration.Ping == nil ,
|
|
|
|
// the affectation would make factory.pingHandle become a typed nil, which does not pass the nil test,
|
|
|
|
// and would break things elsewhere.
|
|
|
|
if staticConfiguration.Ping != nil {
|
|
|
|
factory.pingHandler = staticConfiguration.Ping
|
|
|
|
}
|
2019-11-14 15:40:05 +00:00
|
|
|
|
|
|
|
return factory
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build creates a service manager.
|
|
|
|
func (f *ManagerFactory) Build(configuration *runtime.Configuration) *InternalHandlers {
|
2024-09-26 09:00:05 +00:00
|
|
|
svcManager := NewManager(configuration.Services, f.observabilityMgr, f.routinesPool, f.transportManager, f.proxyBuilder)
|
2020-10-29 14:40:04 +00:00
|
|
|
|
|
|
|
var apiHandler http.Handler
|
|
|
|
if f.api != nil {
|
|
|
|
apiHandler = f.api(configuration)
|
|
|
|
}
|
|
|
|
|
|
|
|
return NewInternalHandlers(svcManager, apiHandler, f.restHandler, f.metricsHandler, f.pingHandler, f.dashboardHandler, f.acmeHTTPHandler)
|
2019-11-14 15:40:05 +00:00
|
|
|
}
|