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

Unified Diff: server/templates/middleware.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 | « server/settings/admin/settings.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: server/templates/middleware.go
diff --git a/server/templates/middleware.go b/server/templates/middleware.go
index fcd6398329f4ada4fd667c54d1fe18a30cd94011..be79abf3557ddb48f787e71a44257e7fc9b156ad 100644
--- a/server/templates/middleware.go
+++ b/server/templates/middleware.go
@@ -1,31 +1,28 @@
// 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 templates
import (
"fmt"
"net/http"
- "github.com/julienschmidt/httprouter"
- "golang.org/x/net/context"
-
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
)
// WithTemplates is middleware that lazily loads template bundle and injects it
// into the context.
//
// Wrapper reply with HTTP 500 if templates can not be loaded. Inner handler
// receives context with all templates successfully loaded.
-func WithTemplates(h middleware.Handler, b *Bundle) middleware.Handler {
- return func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
- c = Use(c, b) // calls EnsureLoaded and initializes b.err inside
+func WithTemplates(b *Bundle) router.Middleware {
+ return func(c *router.Context, next router.Handler) {
+ c.Context = Use(c.Context, b) // calls EnsureLoaded and initializes b.err inside
if b.err != nil {
- http.Error(rw, fmt.Sprintf("Can't load HTML templates.\n%s", b.err), http.StatusInternalServerError)
+ http.Error(c.Writer, fmt.Sprintf("Can't load HTML templates.\n%s", b.err), http.StatusInternalServerError)
return
}
- h(c, rw, r, p)
+ next(c)
}
}
« no previous file with comments | « server/settings/admin/settings.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698