-
Notifications
You must be signed in to change notification settings - Fork 454
/
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)
}