router.go 866 B

123456789101112131415161718192021222324252627
  1. package app
  2. import (
  3. "file_upload/backend/app/controller"
  4. "file_upload/backend/app/middlewares"
  5. "file_upload/backend/app/router"
  6. "file_upload/backend/global"
  7. "github.com/gin-contrib/static"
  8. "github.com/gin-gonic/gin"
  9. )
  10. func InitRouter() error {
  11. engine := gin.New()
  12. //记录日志
  13. engine.Use(middleware.Cors())
  14. //配置前端静态资源目录
  15. engine.StaticFile("/", "./frontend/dist/index.html")
  16. engine.Static("/assets", "./frontend/dist/assets")
  17. engine.Static("/libs", "./frontend/dist/libs")
  18. engine.StaticFile("/favicon.ico", "./frontend/dist/favicon.ico")
  19. engine.Use(static.Serve("/download/image", static.LocalFile(global.DownloadSetting.Path, true)))
  20. //静态资源访问地址
  21. engine.GET("/download", controller.GetImage)
  22. gin.SetMode(global.ServerSetting.Mode)
  23. router.FileInitRouter(engine)
  24. return engine.Run(global.ServerSetting.Port)
  25. }