文章

Gin 路由命中问题

背景

在 prometheus 监控接口时,需要通过接口 uri 统计。在有 Path Variables(路径参数)的情况下,如果简单使用 c.Request.Method+c.Request.URL.Path 来统计,会导致一些使用了路径参数的接口没有被归为同一个。

解决方案

c.Request.Method+" "+c.FullPath()

Ref

Get matched route in context · Issue #748 · gin-gonic/gin · GitHub
go - Gin send metrics to promethesus where the URL has a parameter in the path - Stack Overflow

License:  CC BY 4.0