附近小店
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 

79 řádky
2.2 KiB

  1. package router
  2. import (
  3. "applet/app/cfg"
  4. "applet/app/hdl"
  5. "applet/app/mw"
  6. _ "applet/docs"
  7. "github.com/gin-gonic/gin"
  8. )
  9. // 初始化路由
  10. // 1
  11. func Init() *gin.Engine {
  12. // debug, release, test 项目阶段
  13. mode := "release"
  14. if cfg.Debug {
  15. mode = "debug"
  16. }
  17. gin.SetMode(mode)
  18. //创建一个新的启动器
  19. r := gin.New()
  20. r.Use(mw.ChangeHeader)
  21. // 是否打印访问日志, 在非正式环境都打印
  22. if mode != "release" {
  23. r.Use(gin.Logger())
  24. }
  25. r.Use(gin.Recovery())
  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. routeCommunityTeam(r.Group("/api/v1/communityTeam"))
  37. return r
  38. }
  39. func routeCommunityTeam(r *gin.RouterGroup) {
  40. r.Use(mw.DB) // 下面接口再根据mid 获取数据库名
  41. r.Use(mw.CheckBody) //body参数转换
  42. r.Use(mw.CheckSign) //签名校验
  43. r.Use(mw.Checker)
  44. r.POST("/city", hdl.City)
  45. r.GET("/bank/store/cate", hdl.BankStoreCate)
  46. r.POST("/bank/store/list", hdl.BankStore)
  47. r.POST("/store", hdl.Store)
  48. r.POST("/store/like/list", hdl.StoreLike)
  49. r.GET("/goods/cate", hdl.Cate)
  50. r.POST("/goods", hdl.Goods)
  51. r.POST("/goods/sku", hdl.GoodsSku)
  52. r.POST("/coupon", hdl.Coupon)
  53. r.GET("/user", hdl.User)
  54. // 用户授权后调用的接口
  55. r.Use(mw.AuthJWT)
  56. r.POST("/coupon/receive", hdl.CouponReceive)
  57. r.POST("/store/addLike", hdl.StoreAddLike)
  58. r.POST("/store/cancelLike", hdl.StoreCancelLike)
  59. r.POST("/goods/coupon", hdl.GoodsCoupon)
  60. r.POST("/order/total", hdl.OrderTotal)
  61. r.POST("/order/create", hdl.OrderCreate)
  62. r.POST("/order/cancel", hdl.OrderCancel)
  63. r.POST("/order/confirm", hdl.OrderConfirm)
  64. r.POST("/order/coupon", hdl.OrderCoupon)
  65. r.POST("/order/list", hdl.OrderList)
  66. r.POST("/order/detail", hdl.OrderDetail)
  67. r.GET("/order/cate", hdl.OrderCate)
  68. r.POST("/pay/:payMethod/:orderType", hdl.Pay)
  69. r.POST("/store/order/list", hdl.StoreOrderList)
  70. r.POST("/store/order/detail", hdl.StoreOrderDetail)
  71. r.POST("/store/order/confirm", hdl.StoreOrderConfirm)
  72. r.GET("/store/order/cate", hdl.StoreOrderCate)
  73. }