forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy_factory.go
36 lines (30 loc) · 1.51 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
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"
)
// 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 := 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 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)
}