1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- package router
- import (
- "github.com/gin-gonic/gin"
- file "iot_manager_service/app/file/controller"
- "iot_manager_service/app/middleware"
- user "iot_manager_service/app/user/controller"
- "iot_manager_service/config"
- "iot_manager_service/util/logger"
- "iot_manager_service/util/websocket"
- )
- func InitRouter(engine *gin.Engine) {
- // 跨域处理
- engine.Use(middleware.Cors())
- // 校验token令牌
- engine.Use(middleware.AuthMiddleware())
- engine.Use(gin.Recovery())
- if config.Instance().Logger.Switch == 1 {
- engine.Use(logger.LogToFile())
- }
- engine.Use(logger.Recover)
- //用户
- sys := engine.Group("/user")
- {
- sys.GET("/getPublicKey", user.SysUserController.GetPublicKey)
- sys.POST("/login", user.SysUserController.Login)
- sys.POST("/logout", user.SysUserController.Logout)
- sys.POST("/getDeptUsers", user.SysUserController.GetDeptSysUsers)
- sys.GET("/getNewTokens", user.SysUserController.GetNewTokens)
- sys.GET("/getUser", user.SysUserController.GetSysUser)
- }
- //文件
- files := engine.Group("/file")
- {
- files.POST("/distribute", file.FileController.Distribute)
- files.POST("/getUserFiles", file.FileController.GetSysUserFiles)
- files.GET("/viewFile", middleware.CheckAuth(), file.FileController.ViewFile)
- files.GET("/downloadFile", middleware.CheckAuth(), file.FileController.DownloadFile)
- files.POST("/forwardingFile", middleware.CheckAuth(), file.FileController.ForwardingFile)
- }
- //下发通知
- notice := engine.Group("/notice")
- {
- //请求Websocket连接
- notice.GET("/websocket", websocket.HandleWebSocket)
- }
- }
|