82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package routes
|
|
|
|
/**
|
|
* 配置路由
|
|
*/
|
|
import (
|
|
"qteam/app/constants/common"
|
|
"qteam/app/http/controllers"
|
|
"qteam/app/http/controllers/front"
|
|
"qteam/app/http/middlewares"
|
|
"qteam/app/http/trace"
|
|
"qteam/app/utils/metric"
|
|
"qteam/config"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/qit-team/snow-core/http/middleware"
|
|
"github.com/qit-team/snow-core/log/logger"
|
|
"github.com/swaggo/gin-swagger"
|
|
"github.com/swaggo/gin-swagger/swaggerFiles"
|
|
)
|
|
|
|
// api路由配置
|
|
func RegisterRoute(router *gin.Engine) {
|
|
//middleware: 服务错误处理 => 生成请求id => access log
|
|
router.Use(middlewares.ServerRecovery(), middleware.GenRequestId, middleware.GenContextKit, middleware.AccessLog())
|
|
|
|
if config.GetConf().PrometheusCollectEnable && config.IsEnvEqual(config.ProdEnv) {
|
|
router.Use(middlewares.CollectMetric())
|
|
metric.Init(metric.EnableRuntime(), metric.EnableProcess())
|
|
metricHandler := metric.Handler()
|
|
router.GET("/metrics", func(ctx *gin.Context) {
|
|
metricHandler.ServeHTTP(ctx.Writer, ctx.Request)
|
|
})
|
|
}
|
|
|
|
if len(config.GetConf().SkyWalkingOapServer) > 0 && config.IsEnvEqual(config.ProdEnv) {
|
|
err := trace.InitTracer(config.GetConf().ServiceName, config.GetConf().SkyWalkingOapServer)
|
|
if err != nil {
|
|
logger.Error(nil, "InitTracer", err.Error())
|
|
} else {
|
|
router.Use(middlewares.Trace())
|
|
}
|
|
}
|
|
|
|
router.Use(middlewares.Cors())
|
|
router.NoRoute(controllers.Error404)
|
|
|
|
//api版本
|
|
v1 := router.Group(common.FRONT_API_V1, middlewares.ValidateRequest())
|
|
{
|
|
//优惠券品牌、商品列表
|
|
v1.POST("/VoucherList", front.VoucherList)
|
|
// 联合登录
|
|
v1.POST("/UnionLogin", front.UnionLogin)
|
|
// 订单回调
|
|
v1.POST("/order/notify", front.OrderNotify)
|
|
//商品详情
|
|
v1.POST("/product/detail", front.ProductDetail)
|
|
|
|
//auth
|
|
//auth := v1.Group("auth")
|
|
auth := v1.Group("auth", middlewares.Auth())
|
|
{
|
|
order := auth.Group("/order")
|
|
{
|
|
order.POST("/create", front.CreateOrder)
|
|
order.POST("/list", front.OrderList)
|
|
order.POST("/query", front.OrderQuery)
|
|
order.POST("/refund", front.OrderRefund)
|
|
}
|
|
}
|
|
}
|
|
|
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
|
|
|
//router.GET("/hello", controllers.HelloHandler)
|
|
//router.GET("/create", controllers.HelloCreateHandler)
|
|
//router.GET("/update", controllers.UpdateHandler)
|
|
//router.GET("/delete", controllers.DeleteHandler)
|
|
//router.GET("/query", controllers.QueryHandler)
|
|
}
|