forked from krakend/krakend-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
router_engine.go
42 lines (31 loc) · 1.1 KB
/
router_engine.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 (
"io"
botdetector "github.com/devopsfaith/krakend-botdetector/gin"
httpsecure "github.com/devopsfaith/krakend-httpsecure/gin"
lua "github.com/devopsfaith/krakend-lua/router/gin"
"github.com/gin-gonic/gin"
"github.com/luraproject/lura/config"
"github.com/luraproject/lura/logging"
)
// NewEngine creates a new gin engine with some default values and a secure middleware
func NewEngine(cfg config.ServiceConfig, logger logging.Logger, w io.Writer) *gin.Engine {
if !cfg.Debug {
gin.SetMode(gin.ReleaseMode)
}
engine := gin.New()
engine.Use(gin.LoggerWithConfig(gin.LoggerConfig{Output: w}), gin.Recovery())
engine.RedirectTrailingSlash = true
engine.RedirectFixedPath = true
engine.HandleMethodNotAllowed = true
if err := httpsecure.Register(cfg.ExtraConfig, engine); err != nil {
logger.Warning(err)
}
lua.Register(logger, cfg.ExtraConfig, engine)
botdetector.Register(cfg, logger, engine)
return engine
}
type engineFactory struct{}
func (e engineFactory) NewEngine(cfg config.ServiceConfig, l logging.Logger, w io.Writer) *gin.Engine {
return NewEngine(cfg, l, w)
}