forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_factory.go
46 lines (39 loc) · 2 KB
/
handler_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
44
45
46
package krakend
import (
"fmt"
ipfilter "github.com/Noah-Labs-Development/krakend-ipfilter"
sizelimit "github.com/Noah-Labs-Development/krakend-sizelimit"
botdetector "github.com/krakendio/krakend-botdetector/v2/gin"
jose "github.com/krakendio/krakend-jose/v2"
ginjose "github.com/krakendio/krakend-jose/v2/gin"
lua "github.com/krakendio/krakend-lua/v2/router/gin"
metrics "github.com/krakendio/krakend-metrics/v2/gin"
opencensus "github.com/krakendio/krakend-opencensus/v2/router/gin"
juju "github.com/krakendio/krakend-ratelimit/v2/juju/router/gin"
"github.com/luraproject/lura/v2/config"
"github.com/luraproject/lura/v2/logging"
"github.com/luraproject/lura/v2/proxy"
router "github.com/luraproject/lura/v2/router/gin"
"github.com/luraproject/lura/v2/transport/http/server"
"github.com/gin-gonic/gin"
)
// NewHandlerFactory returns a HandlerFactory with a rate-limit and a metrics collector middleware injected
func NewHandlerFactory(logger logging.Logger, metricCollector *metrics.Metrics, rejecter jose.RejecterFactory) router.HandlerFactory {
handlerFactory := router.CustomErrorEndpointHandler(logger, server.DefaultToHTTPError)
handlerFactory = juju.NewRateLimiterMw(logger, handlerFactory)
handlerFactory = lua.HandlerFactory(logger, handlerFactory)
handlerFactory = ginjose.HandlerFactory(handlerFactory, logger, rejecter)
handlerFactory = metricCollector.NewHTTPHandlerFactory(handlerFactory)
handlerFactory = opencensus.New(handlerFactory)
handlerFactory = ipfilter.HandlerFactory(handlerFactory, logger)
handlerFactory = botdetector.New(handlerFactory, logger)
handlerFactory = sizelimit.HandlerFactory(handlerFactory)
return func(cfg *config.EndpointConfig, p proxy.Proxy) gin.HandlerFunc {
logger.Debug(fmt.Sprintf("[ENDPOINT: %s] Building the http handler", cfg.Endpoint))
return handlerFactory(cfg, p)
}
}
type handlerFactory struct{}
func (handlerFactory) NewHandlerFactory(l logging.Logger, m *metrics.Metrics, r jose.RejecterFactory) router.HandlerFactory {
return NewHandlerFactory(l, m, r)
}