mirror of
https://github.com/gogs/gogs.git
synced 2026-05-06 15:06:53 +02:00
30 lines
582 B
Go
30 lines
582 B
Go
package app
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/flamego/flamego"
|
|
|
|
"gogs.io/gogs/internal/authutil"
|
|
"gogs.io/gogs/internal/conf"
|
|
)
|
|
|
|
func MetricsFilter() flamego.Handler {
|
|
return func(w http.ResponseWriter, r *http.Request) {
|
|
if !conf.Prometheus.Enabled {
|
|
w.WriteHeader(http.StatusNotFound)
|
|
return
|
|
}
|
|
|
|
if !conf.Prometheus.EnableBasicAuth {
|
|
return
|
|
}
|
|
|
|
username, password := authutil.DecodeBasic(r.Header)
|
|
if username != conf.Prometheus.BasicAuthUsername || password != conf.Prometheus.BasicAuthPassword {
|
|
w.WriteHeader(http.StatusForbidden)
|
|
return
|
|
}
|
|
}
|
|
}
|