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

Unified Diff: appengine/cmd/cron/ui/invocation.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/ui/index.go ('k') | appengine/cmd/cron/ui/job.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/cron/ui/invocation.go
diff --git a/appengine/cmd/cron/ui/invocation.go b/appengine/cmd/cron/ui/invocation.go
index ff9fe101df40ec2018f08d05325014f74bc406e5..14b763fb2fd560a11e49246bb6a0f0156d4e8be8 100644
--- a/appengine/cmd/cron/ui/invocation.go
+++ b/appengine/cmd/cron/ui/invocation.go
@@ -2,72 +2,70 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
package ui
import (
"fmt"
"net/http"
"strconv"
- "github.com/julienschmidt/httprouter"
- "golang.org/x/net/context"
-
"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 invocationPage(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- projectID := p.ByName("ProjectID")
- jobID := p.ByName("JobID")
- invID, err := strconv.ParseInt(p.ByName("InvID"), 10, 64)
+func invocationPage(c *router.Context) {
+ projectID := c.Params.ByName("ProjectID")
+ jobID := c.Params.ByName("JobID")
+ invID, err := strconv.ParseInt(c.Params.ByName("InvID"), 10, 64)
if err != nil {
- http.Error(w, "No such invocation", http.StatusNotFound)
+ http.Error(c.Writer, "No such invocation", http.StatusNotFound)
return
}
- inv, err := config(c).Engine.GetInvocation(c, projectID+"/"+jobID, invID)
+ inv, err := config(c.Context).Engine.GetInvocation(c.Context, projectID+"/"+jobID, invID)
if err != nil {
panic(err)
}
if inv == nil {
- http.Error(w, "No such invocation", http.StatusNotFound)
+ http.Error(c.Writer, "No such invocation", http.StatusNotFound)
return
}
- now := clock.Now(c).UTC()
- templates.MustRender(c, w, "pages/invocation.html", map[string]interface{}{
+ now := clock.Now(c.Context).UTC()
+ templates.MustRender(c.Context, c.Writer, "pages/invocation.html", map[string]interface{}{
"ProjectID": projectID,
"JobID": jobID,
"Inv": makeInvocation(projectID, jobID, inv, now),
})
}
////////////////////////////////////////////////////////////////////////////////
// Actions.
-func abortInvocationAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- handleInvAction(c, w, r, p, func(jobID string, invID int64) error {
- who := auth.CurrentIdentity(c)
- return config(c).Engine.AbortInvocation(c, jobID, invID, who)
+func abortInvocationAction(c *router.Context) {
+ handleInvAction(c, func(jobID string, invID int64) error {
+ who := auth.CurrentIdentity(c.Context)
+ return config(c.Context).Engine.AbortInvocation(c.Context, jobID, invID, who)
})
}
-func handleInvAction(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params, cb func(string, int64) error) {
- projectID := p.ByName("ProjectID")
- jobID := p.ByName("JobID")
- invID := p.ByName("InvID")
- if !isJobOwner(c, projectID, jobID) {
- http.Error(w, "Forbidden", 403)
+func handleInvAction(c *router.Context, cb func(string, int64) error) {
+ projectID := c.Params.ByName("ProjectID")
+ jobID := c.Params.ByName("JobID")
+ invID := c.Params.ByName("InvID")
+ if !isJobOwner(c.Context, projectID, jobID) {
+ http.Error(c.Writer, "Forbidden", 403)
return
}
invIDAsInt, err := strconv.ParseInt(invID, 10, 64)
if err != nil {
- http.Error(w, "Bad invocation ID", 400)
+ http.Error(c.Writer, "Bad invocation ID", 400)
return
}
if err := cb(projectID+"/"+jobID, invIDAsInt); err != nil {
panic(err)
}
- http.Redirect(w, r, fmt.Sprintf("/jobs/%s/%s/%s", projectID, jobID, invID), http.StatusFound)
+ http.Redirect(c.Writer, c.Request, fmt.Sprintf("/jobs/%s/%s/%s", projectID, jobID, invID), http.StatusFound)
}
« no previous file with comments | « appengine/cmd/cron/ui/index.go ('k') | appengine/cmd/cron/ui/job.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698