metrics.go 592 B

1234567891011121314151617181920212223242526272829
  1. // Copyright 2020 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package app
  5. import (
  6. "net/http"
  7. "gopkg.in/macaron.v1"
  8. "gogs.io/gogs/internal/conf"
  9. "gogs.io/gogs/internal/context"
  10. )
  11. func MetricsFilter() macaron.Handler {
  12. return func(c *context.Context) {
  13. if !conf.Prometheus.Enabled {
  14. c.Status(http.StatusNotFound)
  15. return
  16. }
  17. if !conf.Prometheus.EnableBasicAuth {
  18. return
  19. }
  20. c.RequireBasicAuth(conf.Prometheus.BasicAuthUsername, conf.Prometheus.BasicAuthPassword)
  21. }
  22. }