2022-11-13 19:17:07 +01:00
|
|
|
package ginext
|
|
|
|
|
|
|
|
import (
|
|
|
|
scn "blackforestbytes.com/simplecloudnotifier"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-12-09 00:40:50 +01:00
|
|
|
var SuppressGinLogs = false
|
|
|
|
|
2022-11-13 19:17:07 +01:00
|
|
|
func NewEngine(cfg scn.Config) *gin.Engine {
|
|
|
|
engine := gin.New()
|
|
|
|
|
|
|
|
engine.RedirectFixedPath = false
|
|
|
|
engine.RedirectTrailingSlash = false
|
|
|
|
|
2022-12-20 09:22:18 +01:00
|
|
|
if cfg.Cors {
|
|
|
|
engine.Use(CorsMiddleware())
|
|
|
|
}
|
2022-11-13 19:17:07 +01:00
|
|
|
|
|
|
|
if cfg.GinDebug {
|
2022-12-09 00:40:50 +01:00
|
|
|
ginlogger := gin.Logger()
|
|
|
|
engine.Use(func(context *gin.Context) {
|
|
|
|
if SuppressGinLogs {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ginlogger(context)
|
|
|
|
})
|
2022-11-13 19:17:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return engine
|
|
|
|
}
|