附近小店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

router.go 2.0 KiB

2 달 전
2 달 전
2 달 전
2 달 전
2 달 전
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.GET("/goods/cate", hdl.Cate)
  49. r.POST("/goods", hdl.Goods)
  50. r.POST("/goods/sku", hdl.GoodsSku)
  51. // 用户授权后调用的接口
  52. r.Use(mw.AuthJWT)
  53. r.POST("/store/addLike", hdl.StoreAddLike)
  54. r.POST("/store/cancelLike", hdl.StoreCancelLike)
  55. r.POST("/goods/coupon", hdl.GoodsCoupon)
  56. r.POST("/order/total", hdl.OrderTotal)
  57. r.POST("/order/create", hdl.OrderCreate)
  58. r.POST("/order/cancel", hdl.OrderCancel)
  59. r.POST("/order/coupon", hdl.OrderCoupon)
  60. r.POST("/order/list", hdl.OrderList)
  61. r.POST("/order/detail", hdl.OrderDetail)
  62. r.GET("/order/cate", hdl.OrderCate)
  63. r.POST("/pay/:payMethod/:orderType", hdl.Pay)
  64. r.POST("/store/order/list", hdl.StoreOrderList)
  65. r.POST("/store/order/detail", hdl.StoreOrderDetail)
  66. r.POST("/store/order/confirm", hdl.StoreOrderConfirm)
  67. r.GET("/store/order/cate", hdl.StoreOrderCate)
  68. }