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