You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.7 KiB
60 lines
1.7 KiB
package router
|
|
|
|
import (
|
|
"epur-pay/cache"
|
|
_ "epur-pay/docs"
|
|
"epur-pay/pkg/config"
|
|
"epur-pay/pkg/dapi"
|
|
"github.com/gin-contrib/gzip"
|
|
"github.com/gin-gonic/gin"
|
|
cors "github.com/itsjamie/gin-cors"
|
|
swaggerFiles "github.com/swaggo/files"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
)
|
|
|
|
func Router() *gin.Engine {
|
|
|
|
gin.SetMode(config.Cf.Common.RunMode)
|
|
|
|
engine := gin.New()
|
|
engine.Use(Logs(), cors.Middleware(cors.Config{
|
|
ValidateHeaders: false,
|
|
Origins: "*",
|
|
RequestHeaders: "*",
|
|
ExposedHeaders: "*",
|
|
Methods: "*",
|
|
MaxAge: 0,
|
|
Credentials: false,
|
|
}), gzip.Gzip(gzip.DefaultCompression), IPBlackList(), gin.Recovery())
|
|
|
|
goApi := engine.Group("/api/v1")
|
|
goApi.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
NewRouterFunc()
|
|
for index, item := range cache.Global.Routers {
|
|
var apiRouter *gin.RouterGroup
|
|
if !item.Leaf {
|
|
apiRouter = goApi.Group(item.Path)
|
|
for indexChild, itemChild := range item.Child {
|
|
item.Child[indexChild].Params.(*dapi.InParams).SaveEvent = itemChild.Name
|
|
switch itemChild.Method {
|
|
case "POST":
|
|
apiRouter.POST(itemChild.Path, dapi.ApiDecorator(itemChild.F, itemChild.Params.(*dapi.InParams)))
|
|
default:
|
|
apiRouter.GET(itemChild.Path, dapi.ApiDecorator(itemChild.F, itemChild.Params.(*dapi.InParams)))
|
|
}
|
|
}
|
|
} else {
|
|
apiRouter = goApi
|
|
cache.Global.Routers[index].Params.(*dapi.InParams).SaveEvent = item.Name
|
|
switch item.Method {
|
|
case "POST":
|
|
apiRouter.POST(item.Path, dapi.ApiDecorator(item.F, item.Params.(*dapi.InParams)))
|
|
default:
|
|
apiRouter.GET(item.Path, dapi.ApiDecorator(item.F, item.Params.(*dapi.InParams)))
|
|
}
|
|
}
|
|
}
|
|
|
|
return engine
|
|
}
|