router.go 938 B

1234567891011121314151617181920212223242526272829
  1. package app
  2. import (
  3. "bigdata_archives/app/controller"
  4. middlewares "bigdata_archives/app/middleware"
  5. "bigdata_archives/app/routers"
  6. "bigdata_archives/configs"
  7. "github.com/gin-gonic/gin"
  8. )
  9. func InitRouter() error {
  10. engine := gin.New()
  11. gin.SetMode(configs.Config.GetString("server.mode"))
  12. engine.Use(middlewares.Cors())
  13. //配置前端静态资源
  14. engine.StaticFile("/", "./frontend/dist/index.html")
  15. engine.Static("/assets", "./frontend/dist/assets")
  16. engine.Static("/libs", "./frontend/dist/libs")
  17. engine.StaticFile("/favicon.ico", "./frontend/dist/favicon.ico")
  18. //图片静态资源访问
  19. engine.Static("/image", "./image")
  20. engine.GET("/ws/temperature-humidity", controller.WebSocketHandler)
  21. routers.UserRouter(engine)
  22. routers.MonitorRouter(engine)
  23. engine.Use(middlewares.AdminMiddleware())
  24. routers.SystemRouter(engine)
  25. routers.TemperatureRouter(engine)
  26. return engine.Run(configs.Config.GetString("server.port"))
  27. }