SimpleCloudNotifier/server/api/ginext/gin.go

32 lines
500 B
Go
Raw Normal View History

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
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
}