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.UserController.GetPublicKey)
- sys.POST("/login", user.UserController.Login)
- sys.POST("/logout", user.UserController.Logout)
- sys.GET("/getdeptusers", user.UserController.GetDeptUsers)
- sys.GET("/getnewtokens", user.UserController.GetNewTokens)
- }
- //文件
- files := engine.Group("/file")
- {
- files.POST("/distribute", file.FileController.Distribute)
- files.GET("/getuserfiles", file.FileController.GetUserFiles)
- 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)
- notice.GET("/demo", user.UserController.GetUser)
- }
- }
|