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

Unified Diff: appengine/gaemiddleware/context.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/gaemiddleware/appengine_test.go ('k') | appengine/gaemiddleware/routes.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/gaemiddleware/context.go
diff --git a/appengine/gaemiddleware/context.go b/appengine/gaemiddleware/context.go
index 60a8bce83791c2a309cd777a9bd2c7ade7e19373..beffeacf1b1d2115fc0c5fb2a6ab13232005e4e2 100644
--- a/appengine/gaemiddleware/context.go
+++ b/appengine/gaemiddleware/context.go
@@ -1,37 +1,36 @@
// 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 gaemiddleware
import (
"net/http"
- "google.golang.org/appengine"
-
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
+ "google.golang.org/appengine"
"github.com/luci/gae/filter/dscache"
"github.com/luci/gae/impl/prod"
"github.com/luci/luci-go/appengine/gaeauth/client"
"github.com/luci/luci-go/appengine/gaeauth/server"
"github.com/luci/luci-go/appengine/gaeauth/server/gaesigner"
"github.com/luci/luci-go/appengine/gaesecrets"
"github.com/luci/luci-go/appengine/gaesettings"
"github.com/luci/luci-go/appengine/tsmon"
"github.com/luci/luci-go/common/cacheContext"
"github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/server/auth"
"github.com/luci/luci-go/server/middleware"
"github.com/luci/luci-go/server/proccache"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/luci-go/server/settings"
)
var (
// globalProcessCache holds state cached between requests.
globalProcessCache = &proccache.Cache{}
// globalSettings holds global app settings lazily updated from the datastore.
globalSettings = settings.New(gaesettings.Storage{})
@@ -67,23 +66,27 @@ func WithProd(c context.Context, req *http.Request) context.Context {
// The rest of the service may use applied configuration.
c = proccache.Use(c, globalProcessCache)
c = client.UseAnonymousTransport(c)
c = gaesecrets.Use(c, nil)
c = gaesigner.Use(c)
c = auth.UseDB(c, globalAuthDBCache)
return cacheContext.Wrap(c)
}
-// BaseProd adapts a middleware-style handler to a httprouter.Handle.
-//
-// It installs services using WithProd, installs a panic catcher if this
-// is not a devserver, and injects the monitoring middleware.
-func BaseProd(h middleware.Handler) httprouter.Handle {
- h = globalTsMonState.Middleware(h)
- if !appengine.IsDevAppServer() {
- h = middleware.WithPanicCatcher(h)
+// ProdServices is a middleware that installs the set of standard production
+// AppEngine services by calling WithProd.
+func ProdServices(c *router.Context, next router.Handler) {
+ c.Context = WithProd(c.Context, c.Request)
+ next(c)
+}
+
+// BaseProd returns a list of middleware: WithProd middleware, a panic catcher if this
+// is not a devserver, and the monitoring middleware.
+func BaseProd() router.MiddlewareChain {
+ if appengine.IsDevAppServer() {
+ return router.MiddlewareChain{ProdServices, globalTsMonState.Middleware}
}
- return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params) {
- h(WithProd(context.Background(), r), rw, r, p)
+ return router.MiddlewareChain{
+ ProdServices, middleware.WithPanicCatcher, globalTsMonState.Middleware,
}
}
« no previous file with comments | « appengine/gaemiddleware/appengine_test.go ('k') | appengine/gaemiddleware/routes.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698