0c9f256dfc
对应体检报告 #10-#24,一次性完成 v1.1.0 全部 13 项: - #10 storage/cache/redis/jwt/logger 五组件 Manager 化(XxxManager + DefaultXxx + SetDefaultXxxManager,包级 facade 保留兼容) - #11 删除 wire 包 + 清理 StartServerWithPort/GracefulShutdown 双轨 - #12 Lifecycle Hooks(OnInit/OnStart/OnReady/OnStop) - #13 Server 参数配置化(timeout/TLS/unix_socket/response_mode) - #14 JWTConfig.Expire 改 time.Duration + 删 AppConfig.TokenExpire - #15 response Mode 开关(ModeBusiness/ModeREST) - #16 Config.Validate 启动期校验 - #17 livez/readyz 探针路由 - #18 Prometheus metrics 中间件 + /metrics - #19 请求级 Timeout 中间件 - #21 主库探活 + replica 健康剔除 - #22 App.Go + in-flight goroutine 管理 - #24 RequestID 默认装入 + #23 核对 Breaking:删 wire、删 TokenExpire、JWTConfig.Expire 类型变更、删双轨函数。 详见 CHANGELOG 升级说明。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
28 lines
858 B
Go
28 lines
858 B
Go
package router
|
|
|
|
import (
|
|
"github.com/EthanCodeCraft/xlgo-core/middleware"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
|
)
|
|
|
|
// RegisterMetricsRoute 注册 Prometheus 指标暴露端点与采集中间件(#18)。
|
|
//
|
|
// 默认路径 /metrics。传入 path 可自定义。同时把 Metrics() 中间件挂到该组,
|
|
// 这样只有业务路由被统计,/metrics 自身与 /health 等基础路由不计入。
|
|
//
|
|
// 用法:
|
|
//
|
|
// router.RegisterMetricsRoute(r) // /metrics
|
|
// router.RegisterMetricsRoute(r, "/metrics") // 等价
|
|
func RegisterMetricsRoute(r *gin.Engine, path ...string) {
|
|
p := "/metrics"
|
|
if len(path) > 0 && path[0] != "" {
|
|
p = path[0]
|
|
}
|
|
// 指标采集中间件挂在根引擎,统计所有业务请求
|
|
r.Use(middleware.Metrics())
|
|
r.GET(p, gin.WrapH(promhttp.Handler()))
|
|
}
|