Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Unified Diff: appengine/tsmon/handler.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/tsmon/handler.go
diff --git a/appengine/tsmon/handler.go b/appengine/tsmon/handler.go
index 462af8a0f4658e669f5c9417d0bfef94cd8fd659..13c7a17e7a8c309e6e0c2823add984073af9a3c3 100644
--- a/appengine/tsmon/handler.go
+++ b/appengine/tsmon/handler.go
@@ -7,7 +7,6 @@ package tsmon
import (
"net/http"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"github.com/luci/gae/service/datastore"
@@ -16,29 +15,30 @@ import (
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/common/parallel"
"github.com/luci/luci-go/common/tsmon"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
)
// InstallHandlers installs HTTP handlers for tsmon routes.
-func InstallHandlers(r *httprouter.Router, base middleware.Base) {
- r.GET("/internal/cron/ts_mon/housekeeping", base(housekeepingHandler))
+func InstallHandlers(r *router.Router, handlers []router.Handler) {
+ r.GET("/internal/cron/ts_mon/housekeeping", append(handlers, housekeepingHandler)...)
}
// housekeepingHandler is an HTTP handler that should be run every minute by
// cron on App Engine. It assigns task numbers to datastore entries, and runs
// any global metric callbacks.
-func housekeepingHandler(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
- if !info.Get(c).IsDevAppServer() && r.Header.Get("X-Appengine-Cron") != "true" {
- rw.WriteHeader(http.StatusForbidden)
- http.Error(rw, "request not made from cron", http.StatusForbidden)
+func housekeepingHandler(c *router.Context) {
+ if !info.Get(c.Context).IsDevAppServer() && c.Request.Header.Get("X-Appengine-Cron") != "true" {
+ c.Writer.WriteHeader(http.StatusForbidden)
+ http.Error(c.Writer, "request not made from cron", http.StatusForbidden)
+ c.Abort()
return
}
- if err := assignTaskNumbers(c); err != nil {
- rw.WriteHeader(http.StatusInternalServerError)
+ if err := assignTaskNumbers(c.Context); err != nil {
+ c.Writer.WriteHeader(http.StatusInternalServerError)
}
- tsmon.GetState(c).RunGlobalCallbacks(c)
+ tsmon.GetState(c.Context).RunGlobalCallbacks(c.Context)
}
// assignTaskNumbers does some housekeeping on the datastore entries for App

Powered by Google App Engine
This is Rietveld 408576698