-
Notifications
You must be signed in to change notification settings - Fork 454
/
proxy_factory.go
43 lines (35 loc) · 1.75 KB
/
proxy_factory.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package krakend
import (
"fmt"
cel "github.com/krakendio/krakend-cel/v2"
jsonschema "github.com/krakendio/krakend-jsonschema/v2"
lua "github.com/krakendio/krakend-lua/v2/proxy"
metrics "github.com/krakendio/krakend-metrics/v2/gin"
opencensus "github.com/krakendio/krakend-opencensus/v2"
"github.com/luraproject/lura/v2/config"
"github.com/luraproject/lura/v2/logging"
"github.com/luraproject/lura/v2/proxy"
)
func internalNewProxyFactory(logger logging.Logger, backendFactory proxy.BackendFactory,
metricCollector *metrics.Metrics) proxy.Factory {
proxyFactory := proxy.NewDefaultFactory(backendFactory, logger)
proxyFactory = proxy.NewShadowFactory(proxyFactory)
proxyFactory = jsonschema.ProxyFactory(logger, proxyFactory)
proxyFactory = cel.ProxyFactory(logger, proxyFactory)
proxyFactory = lua.ProxyFactory(logger, proxyFactory)
proxyFactory = metricCollector.ProxyFactory("pipe", proxyFactory)
proxyFactory = opencensus.ProxyFactory(proxyFactory)
return proxyFactory
}
// NewProxyFactory returns a new ProxyFactory wrapping the injected BackendFactory with the default proxy stack and a metrics collector
func NewProxyFactory(logger logging.Logger, backendFactory proxy.BackendFactory, metricCollector *metrics.Metrics) proxy.Factory {
proxyFactory := internalNewProxyFactory(logger, backendFactory, metricCollector)
return proxy.FactoryFunc(func(cfg *config.EndpointConfig) (proxy.Proxy, error) {
logger.Debug(fmt.Sprintf("[ENDPOINT: %s] Building the proxy pipe", cfg.Endpoint))
return proxyFactory.New(cfg)
})
}
type proxyFactory struct{}
func (proxyFactory) NewProxyFactory(logger logging.Logger, backendFactory proxy.BackendFactory, metricCollector *metrics.Metrics) proxy.Factory {
return NewProxyFactory(logger, backendFactory, metricCollector)
}