v0.0.172
This commit is contained in:
42
ginext/engine.go
Normal file
42
ginext/engine.go
Normal file
@@ -0,0 +1,42 @@
|
||||
package ginext
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type GinWrapper struct {
|
||||
engine *gin.Engine
|
||||
SuppressGinLogs bool
|
||||
|
||||
allowCors bool
|
||||
ginDebug bool
|
||||
returnRawErrors bool
|
||||
}
|
||||
|
||||
func NewEngine(allowCors bool, ginDebug bool, returnRawErrors bool) *GinWrapper {
|
||||
engine := gin.New()
|
||||
|
||||
wrapper := &GinWrapper{
|
||||
engine: engine,
|
||||
SuppressGinLogs: false,
|
||||
allowCors: allowCors,
|
||||
ginDebug: ginDebug,
|
||||
returnRawErrors: returnRawErrors,
|
||||
}
|
||||
|
||||
engine.RedirectFixedPath = false
|
||||
engine.RedirectTrailingSlash = false
|
||||
|
||||
if allowCors {
|
||||
engine.Use(CorsMiddleware())
|
||||
}
|
||||
|
||||
if ginDebug {
|
||||
ginlogger := gin.Logger()
|
||||
engine.Use(func(context *gin.Context) {
|
||||
if !wrapper.SuppressGinLogs {
|
||||
ginlogger(context)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return wrapper
|
||||
}
|
Reference in New Issue
Block a user