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

Unified Diff: appengine/cmd/cron/ui/common.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: gaemiddleware: add middleware func for WithProd 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
« no previous file with comments | « appengine/cmd/cron/frontend/handler.go ('k') | appengine/cmd/cron/ui/index.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/cron/ui/common.go
diff --git a/appengine/cmd/cron/ui/common.go b/appengine/cmd/cron/ui/common.go
index 4e21ca07d7957556f9da77dd089fd1617bdc12f5..b603fe8e355097b421bd9091130672cdad6338ed 100644
--- a/appengine/cmd/cron/ui/common.go
+++ b/appengine/cmd/cron/ui/common.go
@@ -1,61 +1,59 @@
// Copyright 2015 The LUCI Authors. All rights reserved.
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
// Package ui implements request handlers that serve user facing HTML pages.
package ui
import (
"strings"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"google.golang.org/appengine"
"github.com/luci/gae/service/info"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/auth/xsrf"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/luci-go/server/templates"
"github.com/luci/luci-go/appengine/cmd/cron/engine"
)
// Config is global configuration of UI handlers.
type Config struct {
Engine engine.Engine
TemplatesPath string // path to templates directory deployed to GAE
}
// InstallHandlers adds HTTP handlers that render HTML pages.
-func InstallHandlers(r *httprouter.Router, base middleware.Base, cfg Config) {
+func InstallHandlers(r *router.Router, base router.MiddlewareChain, cfg Config) {
tmpl := prepareTemplates(cfg.TemplatesPath)
- wrap := func(h middleware.Handler) httprouter.Handle {
- h = auth.Authenticate(h)
- h = templates.WithTemplates(h, tmpl)
- h = middleware.WithContextValue(h, configContextKey(0), &cfg)
- return base(h)
- }
+ m := append(base, func(c *router.Context, next router.Handler) {
+ c.Context = context.WithValue(c.Context, configContextKey(0), &cfg)
+ next(c)
+ }, templates.WithTemplates(tmpl), auth.Authenticate)
- r.GET("/", wrap(indexPage))
- r.GET("/jobs/:ProjectID", wrap(projectPage))
- r.GET("/jobs/:ProjectID/:JobID", wrap(jobPage))
- r.GET("/jobs/:ProjectID/:JobID/:InvID", wrap(invocationPage))
+ r.GET("/", m, indexPage)
+ r.GET("/jobs/:ProjectID", m, projectPage)
+ r.GET("/jobs/:ProjectID/:JobID", m, jobPage)
+ r.GET("/jobs/:ProjectID/:JobID/:InvID", m, invocationPage)
// All POST forms must be protected with XSRF token.
- r.POST("/actions/runJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(runJobAction)))
- r.POST("/actions/pauseJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(pauseJobAction)))
- r.POST("/actions/resumeJob/:ProjectID/:JobID", wrap(xsrf.WithTokenCheck(resumeJobAction)))
- r.POST("/actions/abortInvocation/:ProjectID/:JobID/:InvID", wrap(xsrf.WithTokenCheck(abortInvocationAction)))
+ mxsrf := append(m, xsrf.WithTokenCheck)
+ r.POST("/actions/runJob/:ProjectID/:JobID", mxsrf, runJobAction)
+ r.POST("/actions/pauseJob/:ProjectID/:JobID", mxsrf, pauseJobAction)
+ r.POST("/actions/resumeJob/:ProjectID/:JobID", mxsrf, resumeJobAction)
+ r.POST("/actions/abortInvocation/:ProjectID/:JobID/:InvID", mxsrf, abortInvocationAction)
}
type configContextKey int
// config returns Config passed to InstallHandlers.
func config(c context.Context) *Config {
cfg, _ := c.Value(configContextKey(0)).(*Config)
if cfg == nil {
panic("impossible, configContextKey is not set")
}
« no previous file with comments | « appengine/cmd/cron/frontend/handler.go ('k') | appengine/cmd/cron/ui/index.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698