metrics.go 582 B

1234567891011121314151617181920212223242526272829
  1. package app
  2. import (
  3. "net/http"
  4. "github.com/flamego/flamego"
  5. "gogs.io/gogs/internal/authutil"
  6. "gogs.io/gogs/internal/conf"
  7. )
  8. func MetricsFilter() flamego.Handler {
  9. return func(w http.ResponseWriter, r *http.Request) {
  10. if !conf.Prometheus.Enabled {
  11. w.WriteHeader(http.StatusNotFound)
  12. return
  13. }
  14. if !conf.Prometheus.EnableBasicAuth {
  15. return
  16. }
  17. username, password := authutil.DecodeBasic(r.Header)
  18. if username != conf.Prometheus.BasicAuthUsername || password != conf.Prometheus.BasicAuthPassword {
  19. w.WriteHeader(http.StatusForbidden)
  20. return
  21. }
  22. }
  23. }