diff --git a/middleware.go b/middleware.go index c5a1924..ae85457 100644 --- a/middleware.go +++ b/middleware.go @@ -175,7 +175,8 @@ func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Eng } } -func (p *Prometheus) setMetricsPath(e *gin.Engine) { +// SetMetricsPath set metrics paths +func (p *Prometheus) SetMetricsPath(e *gin.Engine) { if p.listenAddress != "" { p.router.GET(p.MetricsPath, prometheusHandler()) @@ -185,7 +186,8 @@ func (p *Prometheus) setMetricsPath(e *gin.Engine) { } } -func (p *Prometheus) setMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts) { +// SetMetricsPathWithAuth set metrics paths with authentication +func (p *Prometheus) SetMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts) { if p.listenAddress != "" { p.router.GET(p.MetricsPath, gin.BasicAuth(accounts), prometheusHandler()) @@ -338,17 +340,18 @@ func (p *Prometheus) registerMetrics(subsystem string) { // Use adds the middleware to a gin engine. func (p *Prometheus) Use(e *gin.Engine) { - e.Use(p.handlerFunc()) - p.setMetricsPath(e) + e.Use(p.HandlerFunc()) + p.SetMetricsPath(e) } // UseWithAuth adds the middleware to a gin engine with BasicAuth. func (p *Prometheus) UseWithAuth(e *gin.Engine, accounts gin.Accounts) { - e.Use(p.handlerFunc()) - p.setMetricsPathWithAuth(e, accounts) + e.Use(p.HandlerFunc()) + p.SetMetricsPathWithAuth(e, accounts) } -func (p *Prometheus) handlerFunc() gin.HandlerFunc { +// HandlerFunc defines handler function for middleware +func (p *Prometheus) HandlerFunc() gin.HandlerFunc { return func(c *gin.Context) { if c.Request.URL.String() == p.MetricsPath { c.Next()