123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package initialize
- import (
- "AIT/api"
- _ "AIT/docs"
- "AIT/global"
- "AIT/middleware"
- "fmt"
- "github.com/gin-gonic/gin"
- swaggerFiles "github.com/swaggo/files"
- ginSwagger "github.com/swaggo/gin-swagger"
- "net/http"
- )
- func Router() {
- gin.SetMode(gin.ReleaseMode)
- engine := gin.Default()
- //解决跨域
- engine.Use(middleware.Cors())
- //404 NOT FOUND
- engine.NoRoute(func(context *gin.Context) {
- context.String(http.StatusNotFound, "404 not found")
- })
- //swag
- engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
- engine.Static("/file", "./files")
- engine.GET("/ws", WsHandler)
- //group
- v1 := engine.Group("/v1")
- user := v1.Group("/user")
- user.POST("/login", api.GetUser().UserLogin)
- //user.Use(middleware.JwtAuth())
- user.POST("/register", api.GetUser().UseRegister)
- user.POST("/reset", api.GetUser().ResetPassword)
- user.POST("/find", api.GetUser().UserList)
- user.POST("/change/password", api.GetUser().ModePass)
- record := v1.Group("/record")
- record.POST("/create", api.GetRecord().SaveRecord)
- record.POST("/find", api.GetRecord().RecordList)
- record.GET("/:recordId/find", api.GetRecord().GetRecordById)
- err := engine.Run(fmt.Sprintf(":%s", global.Config.Server.Port))
- if err != nil {
- fmt.Printf("%s", err.Error())
- return
- }
- }
|