router.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package router
  2. import (
  3. "github.com/gin-gonic/gin"
  4. file "iot_manager_service/app/file/controller"
  5. "iot_manager_service/app/middleware"
  6. user "iot_manager_service/app/user/controller"
  7. "iot_manager_service/config"
  8. "iot_manager_service/util/logger"
  9. "iot_manager_service/util/websocket"
  10. )
  11. func InitRouter(engine *gin.Engine) {
  12. // 跨域处理
  13. engine.Use(middleware.Cors())
  14. // 校验token令牌
  15. engine.Use(middleware.AuthMiddleware())
  16. engine.Use(gin.Recovery())
  17. if config.Instance().Logger.Switch == 1 {
  18. engine.Use(logger.LogToFile())
  19. }
  20. engine.Use(logger.Recover)
  21. //用户
  22. sys := engine.Group("/user")
  23. {
  24. sys.GET("/getPublicKey", user.SysUserController.GetPublicKey)
  25. sys.POST("/login", user.SysUserController.Login)
  26. sys.POST("/logout", user.SysUserController.Logout)
  27. sys.POST("/getDeptUsers", user.SysUserController.GetDeptSysUsers)
  28. sys.GET("/getNewTokens", user.SysUserController.GetNewTokens)
  29. sys.GET("/getUser", user.SysUserController.GetSysUser)
  30. }
  31. //文件
  32. files := engine.Group("/file")
  33. {
  34. files.POST("/distribute", file.FileController.Distribute)
  35. files.POST("/getUserFiles", file.FileController.GetSysUserFiles)
  36. files.GET("/viewFile", middleware.CheckAuth(), file.FileController.ViewFile)
  37. files.GET("/downloadFile", middleware.CheckAuth(), file.FileController.DownloadFile)
  38. files.POST("/forwardingFile", middleware.CheckAuth(), file.FileController.ForwardingFile)
  39. }
  40. //下发通知
  41. notice := engine.Group("/notice")
  42. {
  43. //请求Websocket连接
  44. notice.GET("/websocket", websocket.HandleWebSocket)
  45. }
  46. }