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

Unified Diff: appengine/cmd/helloworld_mvm/frontend/main.go

Issue 2043423004: Make HTTP middleware easier to use (Closed) Base URL: https://github.com/luci/luci-go@master
Patch Set: Update tests 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/helloworld_mvm/frontend/main.go
diff --git a/appengine/cmd/helloworld_mvm/frontend/main.go b/appengine/cmd/helloworld_mvm/frontend/main.go
index 94255c731276bab14fbed5b375f7d888dfeb7f5a..966392cfa999cbb6a1b0781d4e1ebe2bcbc662eb 100644
--- a/appengine/cmd/helloworld_mvm/frontend/main.go
+++ b/appengine/cmd/helloworld_mvm/frontend/main.go
@@ -10,7 +10,6 @@ import (
"net/http"
"strings"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"google.golang.org/appengine"
@@ -18,7 +17,7 @@ import (
"github.com/luci/luci-go/appengine/gaeauth/server"
"github.com/luci/luci-go/appengine/gaemiddleware"
"github.com/luci/luci-go/server/auth"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
"github.com/luci/luci-go/server/templates"
)
@@ -52,23 +51,25 @@ var templateBundle = &templates.Bundle{
}
// base is the root of the middleware chain.
-func base(h middleware.Handler) httprouter.Handle {
+func base() []router.Handler {
methods := auth.Authenticator{
&server.OAuth2Method{Scopes: []string{server.EmailScope}},
server.CookieAuth,
&server.InboundAppIDAuthMethod{},
}
- h = auth.Use(h, methods)
- h = templates.WithTemplates(h, templateBundle)
- return gaemiddleware.BaseProd(h)
+ return append(
+ gaemiddleware.BaseProd(),
+ templates.WithTemplates(templateBundle),
+ auth.Use(methods),
+ )
}
//// Routes.
func main() {
- router := httprouter.New()
- gaemiddleware.InstallHandlers(router, base)
- router.GET("/", base(auth.Authenticate(indexPage)))
+ router := router.New()
+ gaemiddleware.InstallHandlers(router, base())
+ router.GET("/", append(base(), auth.Authenticate(), indexPage)...)
http.DefaultServeMux.Handle("/", router)
appengine.Main()
@@ -76,6 +77,6 @@ func main() {
//// Handlers.
-func indexPage(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- templates.MustRender(c, w, "pages/index.html", nil)
+func indexPage(c *router.Context) {
+ templates.MustRender(c.Context, c.Writer, "pages/index.html", nil)
}

Powered by Google App Engine
This is Rietveld 408576698