package app import ( "file_upload/backend/app/controller" "file_upload/backend/app/middlewares" "file_upload/backend/app/router" "file_upload/backend/global" "github.com/gin-contrib/static" "github.com/gin-gonic/gin" ) func InitRouter() error { engine := gin.New() //记录日志 engine.Use(middleware.Cors()) //配置前端静态资源目录 engine.StaticFile("/", "./frontend/dist/index.html") engine.Static("/assets", "./frontend/dist/assets") engine.Static("/libs", "./frontend/dist/libs") engine.StaticFile("/favicon.ico", "./frontend/dist/favicon.ico") engine.Use(static.Serve("/download/image", static.LocalFile(global.DownloadSetting.Path, true))) //静态资源访问地址 engine.GET("/download", controller.GetImage) gin.SetMode(global.ServerSetting.Mode) router.FileInitRouter(engine) return engine.Run(global.ServerSetting.Port) }