一物一码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

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