router.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package initialize
  2. import (
  3. "AIT/api"
  4. _ "AIT/docs"
  5. "AIT/global"
  6. "AIT/middleware"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. swaggerFiles "github.com/swaggo/files"
  10. ginSwagger "github.com/swaggo/gin-swagger"
  11. "net/http"
  12. )
  13. func Router() {
  14. gin.SetMode(gin.ReleaseMode)
  15. engine := gin.Default()
  16. //解决跨域
  17. engine.Use(middleware.Cors())
  18. //404 NOT FOUND
  19. engine.NoRoute(func(context *gin.Context) {
  20. context.String(http.StatusNotFound, "404 not found")
  21. })
  22. //swag
  23. engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
  24. engine.Static("/file", "./files")
  25. engine.GET("/ws", WsHandler)
  26. //group
  27. v1 := engine.Group("/v1")
  28. user := v1.Group("/user")
  29. user.POST("/login", api.GetUser().UserLogin)
  30. //user.Use(middleware.JwtAuth())
  31. user.POST("/register", api.GetUser().UseRegister)
  32. user.POST("/reset", api.GetUser().ResetPassword)
  33. user.POST("/find", api.GetUser().UserList)
  34. user.POST("/change/password", api.GetUser().ModePass)
  35. record := v1.Group("/record")
  36. record.POST("/create", api.GetRecord().SaveRecord)
  37. record.POST("/find", api.GetRecord().RecordList)
  38. record.GET("/:recordId/find", api.GetRecord().GetRecordById)
  39. err := engine.Run(fmt.Sprintf(":%s", global.Config.Server.Port))
  40. if err != nil {
  41. fmt.Printf("%s", err.Error())
  42. return
  43. }
  44. }