From fda50d52c839899699b7dd033c0d9b2089a6f8ba Mon Sep 17 00:00:00 2001 From: "Frederick F. Kautz IV" Date: Fri, 24 Apr 2015 00:16:29 -0700 Subject: [PATCH] Add initial framework for quota --- pkg/api/api_generic_handlers.go | 13 +++++++++++++ pkg/api/api_router.go | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pkg/api/api_generic_handlers.go b/pkg/api/api_generic_handlers.go index f7707cd61..8933047ec 100644 --- a/pkg/api/api_generic_handlers.go +++ b/pkg/api/api_generic_handlers.go @@ -145,3 +145,16 @@ func ignoreUnImplementedObjectResources(req *http.Request) bool { } return false } + +type quotaHandler struct { + handler http.Handler +} + +func (h quotaHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { + h.handler.ServeHTTP(w, req) +} + +// QuotaHandler implements quotas +func QuotaHandler(h http.Handler) http.Handler { + return quotaHandler{handler: h} +} diff --git a/pkg/api/api_router.go b/pkg/api/api_router.go index 0e5813a52..fa2fcef44 100644 --- a/pkg/api/api_router.go +++ b/pkg/api/api_router.go @@ -89,5 +89,7 @@ func HTTPHandler(domain string, driver drivers.Driver) http.Handler { log.Fatal(iodine.New(err, map[string]string{"domain": domain})) } - return validateHandler(conf, ignoreResourcesHandler(mux)) + h := validateHandler(conf, ignoreResourcesHandler(mux)) + // quota handler is always last + return QuotaHandler(h) }