XinYeYouKu/app/http/routes/route.go

57 lines
1.5 KiB
Go
Raw Normal View History

2024-06-07 18:24:56 +08:00
package routes
/**
* 配置路由
*/
import (
"qteam/app/http/controllers"
2024-06-11 14:57:08 +08:00
"qteam/app/http/controllers/front"
2024-06-07 18:24:56 +08:00
"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"
)
// 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())
}
}
2024-06-11 14:57:08 +08:00
router.Use(middlewares.Cors())
2024-06-07 18:24:56 +08:00
router.NoRoute(controllers.Error404)
//api版本
2024-06-11 14:57:08 +08:00
v1 := router.Group("/v1", middlewares.ValidateRequest())
{
2024-06-11 18:47:02 +08:00
v1.POST("/xy/login", front.XyLogin)
2024-06-12 19:11:00 +08:00
//auth
auth := v1.Group("auth", middlewares.Auth())
{
auth.POST("/user", front.UserInfo)
auth.POST("/activity", front.ActivityDetail)
}
2024-06-11 14:57:08 +08:00
}
2024-06-07 18:24:56 +08:00
}