113 lines
3.6 KiB
Go
113 lines
3.6 KiB
Go
|
package routes
|
||
|
|
||
|
/**
|
||
|
* 配置路由
|
||
|
*/
|
||
|
import (
|
||
|
"com.snow.auto_monitor/app/http/controllers"
|
||
|
"com.snow.auto_monitor/app/http/middlewares"
|
||
|
"com.snow.auto_monitor/app/http/trace"
|
||
|
"com.snow.auto_monitor/app/utils/metric"
|
||
|
"com.snow.auto_monitor/config"
|
||
|
|
||
|
merCon "com.snow.auto_monitor/app/http/controllers/merchant"
|
||
|
ordersCon "com.snow.auto_monitor/app/http/controllers/orders"
|
||
|
proCon "com.snow.auto_monitor/app/http/controllers/product"
|
||
|
transCon "com.snow.auto_monitor/app/http/controllers/transfersys"
|
||
|
wlCon "com.snow.auto_monitor/app/http/controllers/whitelist"
|
||
|
zlCon "com.snow.auto_monitor/app/http/controllers/zhiliansys"
|
||
|
"github.com/gin-gonic/gin"
|
||
|
"github.com/qit-team/snow-core/http/middleware"
|
||
|
"github.com/qit-team/snow-core/log/logger"
|
||
|
ginSwagger "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(), middlewares.VerifyIp())
|
||
|
|
||
|
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.NoRoute(controllers.Error404)
|
||
|
router.GET("/hello", controllers.HandleHello)
|
||
|
router.POST("/test", controllers.HandleTest)
|
||
|
router.POST("/test_validator", controllers.HandleTestValidator)
|
||
|
|
||
|
//api版本
|
||
|
v1 := router.Group("/v1")
|
||
|
{
|
||
|
v1.GET("/banner_list", controllers.GetBannerList)
|
||
|
}
|
||
|
|
||
|
merchant := router.Group("/merchant")
|
||
|
{
|
||
|
merchant.POST("/get_by_id", merCon.GetById)
|
||
|
merchant.POST("/search", merCon.Search)
|
||
|
merchant.POST("/create", merCon.Create)
|
||
|
// merchant.POST("/update", merCon.Update)
|
||
|
// merchant.POST("/delete", merCon.Delete)
|
||
|
}
|
||
|
|
||
|
orders := router.Group("/orders")
|
||
|
{
|
||
|
orders.POST("/get_by_id", ordersCon.GetById)
|
||
|
orders.POST("/search", ordersCon.Search)
|
||
|
// orders.POST("/create", ordersCon.Create)
|
||
|
// orders.POST("/update", ordersCon.Update)
|
||
|
// orders.POST("/delete", ordersCon.Delete)
|
||
|
}
|
||
|
|
||
|
product := router.Group("/product")
|
||
|
{
|
||
|
product.POST("/get_by_id", proCon.GetById)
|
||
|
product.POST("/search", proCon.Search)
|
||
|
product.POST("/create", proCon.Create)
|
||
|
// product.POST("/update", proCon.Update)
|
||
|
// product.POST("/delete", proCon.Delete)
|
||
|
}
|
||
|
|
||
|
whitelist := router.Group("/whitelist")
|
||
|
{
|
||
|
whitelist.POST("/get_by_id", wlCon.GetById)
|
||
|
whitelist.POST("/search", wlCon.Search)
|
||
|
whitelist.POST("/create", wlCon.Create)
|
||
|
// whitelist.POST("/update", wlCon.Update)
|
||
|
// whitelist.POST("/delete", wlCon.Delete)
|
||
|
}
|
||
|
|
||
|
zhilian := router.Group("/zhilian")
|
||
|
// zhilian.Use(middlewares.VerifySign())
|
||
|
zhilian.Use(middlewares.RequestLog())
|
||
|
{
|
||
|
zhilian.POST("/recharge/order", zlCon.CreateOrder)
|
||
|
zhilian.POST("/recharge/query", zlCon.GetByOutTradeNo)
|
||
|
}
|
||
|
|
||
|
transfersys := router.Group("/transfersys")
|
||
|
transfersys.Use(middlewares.RequestLog())
|
||
|
{
|
||
|
transfersys.GET("/recharge/get_order", transCon.GetOrder)
|
||
|
transfersys.POST("/recharge/finish", transCon.FinishOrder)
|
||
|
}
|
||
|
|
||
|
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||
|
}
|