蛋蛋星球 后台端
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 
 

63 rader
1.5 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/hdl/institutional_management/public_platoon"
  6. "applet/app/mw"
  7. _ "applet/docs"
  8. "github.com/gin-gonic/gin"
  9. swaggerFiles "github.com/swaggo/files"
  10. ginSwagger "github.com/swaggo/gin-swagger"
  11. )
  12. // 初始化路由
  13. func Init() *gin.Engine {
  14. // debug, release, test 项目阶段
  15. mode := "release"
  16. if cfg.Debug {
  17. mode = "debug"
  18. }
  19. gin.SetMode(mode)
  20. //创建一个新的启动器
  21. r := gin.New()
  22. r.GET("/api/swagger/*any", func(c *gin.Context) {
  23. // r.Use(mw.SwagAuth())
  24. ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c)
  25. })
  26. // 是否打印访问日志, 在非正式环境都打印
  27. if mode != "release" {
  28. r.Use(gin.Logger())
  29. }
  30. r.Use(gin.Recovery())
  31. r.GET("/favicon.ico", func(c *gin.Context) {
  32. c.Status(204)
  33. })
  34. r.NoRoute(func(c *gin.Context) {
  35. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  36. })
  37. r.NoMethod(func(c *gin.Context) {
  38. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  39. })
  40. r.Use(mw.Cors)
  41. route(r.Group("/api"))
  42. return r
  43. }
  44. func route(r *gin.RouterGroup) {
  45. r.GET("/test", hdl.Demo)
  46. r.POST("/login", hdl.Login)
  47. rInstitutionalManagement(r.Group("/institutionalManagement"))
  48. r.Use(mw.Auth) // 以下接口需要JWT验证
  49. }
  50. func rInstitutionalManagement(r *gin.RouterGroup) { //制度管理
  51. rPublicPlatoon := r.Group("/publicPlatoon") //公排设置
  52. {
  53. rPublicPlatoon.GET("/getBasic", public_platoon.GetPublicPlatoonBasic)
  54. }
  55. }