quota.go 472 B

123456789101112131415161718192021222324
  1. package middleware
  2. import (
  3. "fmt"
  4. "gopkg.in/macaron.v1"
  5. m "github.com/grafana/grafana/pkg/models"
  6. "github.com/grafana/grafana/pkg/services/quota"
  7. )
  8. func Quota(target string) macaron.Handler {
  9. return func(c *m.ReqContext) {
  10. limitReached, err := quota.QuotaReached(c, target)
  11. if err != nil {
  12. c.JsonApiErr(500, "failed to get quota", err)
  13. return
  14. }
  15. if limitReached {
  16. c.JsonApiErr(403, fmt.Sprintf("%s Quota reached", target), nil)
  17. return
  18. }
  19. }
  20. }