Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,10 @@ func (p *Prometheus) SetListenAddressWithRouter(listenAddress string, r *gin.Eng

// SetMetricsPath set metrics paths
func (p *Prometheus) SetMetricsPath(e *gin.Engine) {
p.setMetricsPath(e)
}

func (p *Prometheus) setMetricsPath(e *gin.Engine) {

if p.listenAddress != "" {
p.router.GET(p.MetricsPath, prometheusHandler())
Expand All @@ -191,6 +195,10 @@ func (p *Prometheus) SetMetricsPath(e *gin.Engine) {

// SetMetricsPathWithAuth set metrics paths with authentication
func (p *Prometheus) SetMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts) {
p.setMetricsPathWithAuth(e, accounts)
}

func (p *Prometheus) setMetricsPathWithAuth(e *gin.Engine, accounts gin.Accounts) {

if p.listenAddress != "" {
p.router.GET(p.MetricsPath, gin.BasicAuth(accounts), prometheusHandler())
Expand Down Expand Up @@ -341,13 +349,13 @@ 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)
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)
p.setMetricsPathWithAuth(e, accounts)
}

// HandlerFunc defines handler function for middleware
Expand Down