package router import ( "fmt" "github.com/gin-contrib/gzip" "github.com/gin-gonic/gin" "icloudapp.cn/tools/middleware" "net/http" ) func InitRouter() *gin.Engine { r := gin.Default() // 上传大小限制 100M r.MaxMultipartMemory = 100 << 20 // 启用gzip压缩 r.Use(gzip.Gzip(gzip.BestCompression)) r.Use(middleware.LoggerMiddleware()) // 错误恢复 r.Use(gin.CustomRecovery(func(ctx *gin.Context, recovered interface{}) { if err, ok := recovered.(string); ok { ctx.String(http.StatusInternalServerError, fmt.Sprintf("error occuring: %s", err)) } ctx.Abort() //c.AbortWithStatus(http.StatusInternalServerError) })) SetupApiRouters(r) SetupPHPRouter(r) return r }