forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_factory.go
42 lines (35 loc) · 1.76 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
package krakend
import (
"fmt"
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 = botdetector.New(handlerFactory, logger)
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)
}