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

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

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Convert remaining source files 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/cmd/cron/ui/job.go
diff --git a/appengine/cmd/cron/ui/job.go b/appengine/cmd/cron/ui/job.go
index b6735f093e323acd42cf21d57041cd39fb6853e6..500fbb3c262393034433afa8cc50956ea7757b78 100644
--- a/appengine/cmd/cron/ui/job.go
+++ b/appengine/cmd/cron/ui/job.go
@@ -11,16 +11,16 @@ import (
"net/http"
"time"
- "github.com/julienschmidt/httprouter"
- "golang.org/x/net/context"
-
"github.com/luci/gae/service/memcache"
"github.com/luci/luci-go/common/clock"
"github.com/luci/luci-go/server/auth"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/luci-go/server/templates"
)
-func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func jobPage(ctx *router.Context) {
+ c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params
+
projectID := p.ByName("ProjectID")
jobID := p.ByName("JobID")
cursor := r.URL.Query().Get("c")
@@ -83,7 +83,9 @@ func jobPage(c context.Context, w http.ResponseWriter, r *http.Request, p httpro
////////////////////////////////////////////////////////////////////////////////
// Actions.
-func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
+func runJobAction(ctx *router.Context) {
+ c, w, r, p := ctx.Context, ctx.Writer, ctx.Request, ctx.Params
+
projectID := p.ByName("ProjectID")
jobID := p.ByName("JobID")
if !isJobOwner(c, projectID, jobID) {
@@ -140,29 +142,29 @@ func runJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p h
}
}
-func pauseJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- handleJobAction(c, w, r, p, func(jobID string) error {
- who := auth.CurrentIdentity(c)
- return config(c).Engine.PauseJob(c, jobID, who)
+func pauseJobAction(c *router.Context) {
+ handleJobAction(c, func(jobID string) error {
+ who := auth.CurrentIdentity(c.Context)
+ return config(c.Context).Engine.PauseJob(c.Context, jobID, who)
})
}
-func resumeJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- handleJobAction(c, w, r, p, func(jobID string) error {
- who := auth.CurrentIdentity(c)
- return config(c).Engine.ResumeJob(c, jobID, who)
+func resumeJobAction(c *router.Context) {
+ handleJobAction(c, func(jobID string) error {
+ who := auth.CurrentIdentity(c.Context)
+ return config(c.Context).Engine.ResumeJob(c.Context, jobID, who)
})
}
-func handleJobAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params, cb func(string) error) {
- projectID := p.ByName("ProjectID")
- jobID := p.ByName("JobID")
- if !isJobOwner(c, projectID, jobID) {
- http.Error(w, "Forbidden", 403)
+func handleJobAction(c *router.Context, cb func(string) error) {
+ projectID := c.Params.ByName("ProjectID")
+ jobID := c.Params.ByName("JobID")
+ if !isJobOwner(c.Context, projectID, jobID) {
+ http.Error(c.Writer, "Forbidden", 403)
return
}
if err := cb(projectID + "/" + jobID); err != nil {
panic(err)
}
- http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s", projectID, jobID), http.StatusFound)
+ http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s", projectID, jobID), http.StatusFound)
}

Powered by Google App Engine
This is Rietveld 408576698