45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package initialization
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/viper"
|
|
swaggerFiles "github.com/swaggo/files"
|
|
ginSwagger "github.com/swaggo/gin-swagger"
|
|
"net/http"
|
|
testdata "testData/api/test.data"
|
|
_ "testData/docs"
|
|
"testData/middleware"
|
|
"testData/model/response"
|
|
"testData/router"
|
|
)
|
|
|
|
func InitRouter() *gin.Engine {
|
|
r := gin.New()
|
|
r.Use(gin.Recovery(), middleware.Cors(), middleware.Log())
|
|
// 判断是否线上环境
|
|
if viper.GetBool("dev") {
|
|
r.GET("/docs/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
}
|
|
r.StaticFS("files", http.Dir("./files"))
|
|
|
|
testData := r.Group("testData")
|
|
{
|
|
router.InitChartRouter(testData)
|
|
router.InitChartSelectionRouter(testData)
|
|
router.InitReportListRouter(testData)
|
|
router.InitReportChartRouter(testData)
|
|
router.InitReportChartSelectionRouter(testData)
|
|
router.InitWarningRouter(testData)
|
|
router.InitFinalReportExcelRouter(testData)
|
|
}
|
|
testDataUpload := r.Group("testData")
|
|
testDataUploadService := testdata.InitUpload()
|
|
{
|
|
testDataUpload.POST("upload", testDataUploadService.UploadAnswerFile)
|
|
}
|
|
r.NoRoute(func(c *gin.Context) {
|
|
response.FailWithMessage("Not Found", c)
|
|
})
|
|
return r
|
|
}
|