-
Notifications
You must be signed in to change notification settings - Fork 455
/
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"
ratelimit "github.com/krakendio/krakend-ratelimit/v3/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 = ratelimit.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)
}