一物一码
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

80 linhas
2.2 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/mw"
  6. "github.com/gin-gonic/gin"
  7. )
  8. //初始化路由
  9. func Init() *gin.Engine {
  10. // debug, release, test 项目阶段
  11. mode := "release"
  12. if cfg.Debug {
  13. mode = "debug"
  14. }
  15. gin.SetMode(mode)
  16. //创建一个新的启动器
  17. r := gin.New()
  18. r.Use(mw.ChangeHeader)
  19. // 是否打印访问日志, 在非正式环境都打印
  20. if mode != "release" {
  21. r.Use(gin.Logger())
  22. }
  23. r.Use(gin.Recovery())
  24. // r.Use(mw.Limiter)
  25. //r.LoadHTMLGlob("static/html/*")
  26. r.GET("/favicon.ico", func(c *gin.Context) {
  27. c.Status(204)
  28. })
  29. r.NoRoute(func(c *gin.Context) {
  30. c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}})
  31. })
  32. r.NoMethod(func(c *gin.Context) {
  33. c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}})
  34. })
  35. r.Use(mw.Cors)
  36. route(r.Group("/api/v1"))
  37. return r
  38. }
  39. func route(r *gin.RouterGroup) {
  40. r.Any("/demo", hdl.Demo)
  41. r.POST("/login", hdl.Login)
  42. r.POST("/img_upload", hdl.ImgUpload)
  43. r.Group("/wx")
  44. {
  45. r.Use(mw.DB)
  46. // 微信公众号消息通知
  47. r.GET("/msgReceive", hdl.WXCheckSignature)
  48. r.POST("/msgReceive", hdl.WXMsgReceive)
  49. }
  50. r.Use(mw.DB) // 以下接口需要用到数据库
  51. {
  52. r.GET("/demo1", hdl.Demo1)
  53. }
  54. r.Use(mw.Checker) // 以下接口需要检查Header: platform
  55. {
  56. }
  57. r.GET("/wechat_menu/get", hdl.GetMenu)
  58. r.POST("/wechat_menu/set", hdl.SetMenu)
  59. r.GET("/qrcodeBatchDownload", hdl.QrcodeBatchDownload) //二维码批次-下载
  60. r.Use(mw.Auth) // 以下接口需要JWT验证
  61. {
  62. r.GET("/userInfo", hdl.UserInfo) //用户信息
  63. r.GET("/sysCfg", hdl.GetSysCfg) //基础配置-获取
  64. r.POST("/sysCfg", hdl.SetSysCfg) //基础配置-设置
  65. r.POST("/qrcodeBatchList", hdl.QrcodeBatchList) //二维码批次-列表
  66. r.GET("/getBatchAddName", hdl.GetBatchAddName) //二维码批次-自动获取添加时名称
  67. r.POST("/qrcodeBatchAdd", hdl.QrcodeBatchAdd) //二维码批次-添加
  68. r.GET("/qrcodeBatchDetail", hdl.QrcodeBatchDetail) //二维码批次-详情
  69. r.DELETE("/qrcodeBatchDelete/:id", hdl.QrcodeBatchDelete) //二维码批次-删除
  70. }
  71. }