package router import ( agentHdl "applet/app/agent/hdl" "applet/app/cfg" "applet/app/hdl" "applet/app/mw" _ "applet/docs" "github.com/gin-gonic/gin" swaggerFiles "github.com/swaggo/files" ginSwagger "github.com/swaggo/gin-swagger" ) // 初始化路由 // 1 func Init() *gin.Engine { // debug, release, test 项目阶段 mode := "release" if cfg.Debug { mode = "debug" } gin.SetMode(mode) //创建一个新的启动器 r := gin.New() r.GET("/api/swagger/*any", func(c *gin.Context) { //r.Use(mw.SwagAuth()) ginSwagger.DisablingWrapHandler(swaggerFiles.Handler, "SWAGGER")(c) }) r.Use(mw.ChangeHeader) // 是否打印访问日志, 在非正式环境都打印 if mode != "release" { r.Use(gin.Logger()) } r.Use(gin.Recovery()) r.GET("/favicon.ico", func(c *gin.Context) { c.Status(204) }) r.NoRoute(func(c *gin.Context) { c.JSON(404, gin.H{"code": 404, "msg": "page not found", "data": []struct{}{}}) }) r.NoMethod(func(c *gin.Context) { c.JSON(405, gin.H{"code": 405, "msg": "method not allowed", "data": []struct{}{}}) }) r.Use(mw.Cors) routeCommunityTeamAgent(r.Group("/api/v1/communityTeam/agent")) routeCommunityTeamOwnStore(r.Group("/api/v1/communityTeam/ownStore")) routeCommunityTeam(r.Group("/api/v1/communityTeam")) return r } func routeCommunityTeamAgent(r *gin.RouterGroup) { r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 r.POST("/login", agentHdl.Login) r.Use(mw.AuthJWT) r.GET("/user", agentHdl.User) r.POST("/service/file/upload", agentHdl.ServiceFileUpload) r.GET("/wechat/base", agentHdl.WechatBase) r.POST("/wechat/base/set", agentHdl.WechatBaseSet) r.GET("/alipay/base", agentHdl.AlipayBase) r.POST("/alipay/base/set", agentHdl.AlipayBaseSet) r.POST("/store/list", agentHdl.UserStoreList) r.POST("/store/save", agentHdl.UserStoreSave) r.POST("/store/order", agentHdl.UserStoreOrder) r.POST("/store/order/detail", agentHdl.UserStoreOrderDetail) r.POST("/store/total", agentHdl.UserStoreTotal) r.POST("/goods/list", agentHdl.Goods) r.POST("/goods/save", agentHdl.GoodsSave) r.POST("/goods/detail", agentHdl.GoodsDetail) r.POST("/goods/del", agentHdl.GoodsDel) r.POST("/goods/cate/list", agentHdl.GoodsCate) r.POST("/goods/cate/save", agentHdl.GoodsCateSave) r.POST("/goods/cate/show", agentHdl.GoodsCateShow) r.POST("/goods/cate/del", agentHdl.GoodsCateDel) } func routeCommunityTeamOwnStore(r *gin.RouterGroup) { } func routeCommunityTeam(r *gin.RouterGroup) { r.Use(mw.DB) // 下面接口再根据mid 获取数据库名 r.Use(mw.CheckBody) //body参数转换 r.Use(mw.CheckSign) //签名校验 r.Use(mw.Checker) r.POST("/city", hdl.City) r.GET("/bank/store/cate", hdl.BankStoreCate) r.POST("/bank/store/list", hdl.BankStore) r.GET("/new/store/cate", hdl.NewStoreCate) r.POST("/new/store/list", hdl.NewStore) r.POST("/store", hdl.Store) r.POST("/store/like/list", hdl.StoreLike) r.GET("/goods/cate", hdl.Cate) r.POST("/goods", hdl.Goods) r.POST("/goods/sku", hdl.GoodsSku) r.POST("/coupon", hdl.Coupon) r.GET("/user", hdl.User) // 用户授权后调用的接口 r.Use(mw.AuthJWT) r.POST("/coupon/receive", hdl.CouponReceive) r.POST("/store/addLike", hdl.StoreAddLike) r.POST("/store/cancelLike", hdl.StoreCancelLike) r.POST("/goods/coupon", hdl.GoodsCoupon) r.POST("/order/total", hdl.OrderTotal) r.POST("/order/create", hdl.OrderCreate) r.POST("/order/cancel", hdl.OrderCancel) r.POST("/order/confirm", hdl.OrderConfirm) r.POST("/order/coupon", hdl.OrderCoupon) r.POST("/order/list", hdl.OrderList) r.POST("/order/detail", hdl.OrderDetail) r.GET("/order/cate", hdl.OrderCate) r.POST("/pay/:payMethod/:orderType", hdl.Pay) r.POST("/store/order/list", hdl.StoreOrderList) r.POST("/store/order/detail", hdl.StoreOrderDetail) r.POST("/store/order/confirm", hdl.StoreOrderConfirm) r.GET("/store/order/cate", hdl.StoreOrderCate) }