add quota middleware to enforce quotas. issue #321

Conflicts:
	pkg/api/api.go
This commit is contained in:
woodsaj
2015-09-11 01:03:47 +08:00
parent 9023171940
commit 0688050552
4 changed files with 41 additions and 2 deletions
+13
View File
@@ -253,3 +253,16 @@ func (ctx *Context) JsonApiErr(status int, message string, err error) {
ctx.JSON(status, resp)
}
func LimitQuota(target m.QuotaTarget) macaron.Handler {
return func(c *Context) {
limitReached, err := m.QuotaReached(c.OrgId, target)
if err != nil {
c.JsonApiErr(500, "failed to get quota", err)
}
if limitReached {
c.JsonApiErr(403, "Quota reached", nil)
return
}
}
}