router.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. )
  10. func InitRouter(engine *gin.Engine) {
  11. // 跨域处理
  12. engine.Use(middleware.Cors())
  13. // 校验token令牌
  14. engine.Use(middleware.AuthMiddleware())
  15. engine.Use(gin.Recovery())
  16. if config.Instance().Logger.Switch == 1 {
  17. engine.Use(logger.LogToFile())
  18. }
  19. engine.Use(logger.Recover)
  20. //用户
  21. sys := engine.Group("/user")
  22. {
  23. sys.GET("/getpublickey", user.UserController.GetPublicKey)
  24. sys.POST("/login", user.UserController.Login)
  25. sys.POST("/logout", user.UserController.Logout)
  26. sys.GET("/getdeptusers", user.UserController.GetDeptUsers)
  27. }
  28. //文件
  29. files := engine.Group("/file")
  30. {
  31. files.POST("/distribute", file.FileController.Distribute)
  32. files.GET("/getuserfiles", file.FileController.GetUserFiles)
  33. }
  34. //通知
  35. notice := engine.Group("/notice")
  36. {
  37. notice.GET("/demo", user.UserController.GetUser)
  38. }
  39. }