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

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: 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/helloworld_mvm/backend/main.go ('k') | appengine/cmd/logdog_coordinator/backend/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..a3a79cadc0973aa4a317adfe371b11ef57352951 100644
--- a/appengine/cmd/helloworld_mvm/frontend/main.go
+++ b/appengine/cmd/helloworld_mvm/frontend/main.go
@@ -3,29 +3,28 @@
// that can be found in the LICENSE file.
// Package main implements HTTP server that handles requests to default
// module.
package main
import (
"net/http"
"strings"
- "github.com/julienschmidt/httprouter"
"golang.org/x/net/context"
"google.golang.org/appengine"
"github.com/luci/gae/service/info"
"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"
)
// templateBundle is used to render HTML templates. It provides a base args
// passed to all templates.
var templateBundle = &templates.Bundle{
Loader: templates.FileSystemLoader("templates"),
DebugMode: appengine.IsDevAppServer(),
DefaultArgs: func(c context.Context) (templates.Args, error) {
loginURL, err := auth.LoginURL(c, "/")
@@ -44,38 +43,41 @@ var templateBundle = &templates.Bundle{
"AppVersion": strings.Split(info.Get(c).VersionID(), ".")[0],
"IsAnonymous": auth.CurrentIdentity(c) == "anonymous:anonymous",
"IsAdmin": isAdmin,
"User": auth.CurrentUser(c),
"LoginURL": loginURL,
"LogoutURL": logoutURL,
}, nil
},
}
-// base is the root of the middleware chain.
-func base(h middleware.Handler) httprouter.Handle {
+// base returns the root middleware chain.
+func base() router.MiddlewareChain {
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)))
- http.DefaultServeMux.Handle("/", router)
+ r := router.New()
+ basemw := base()
+ gaemiddleware.InstallHandlers(r, basemw)
+ r.GET("/", append(basemw, auth.Authenticate), indexPage)
+ http.DefaultServeMux.Handle("/", r)
appengine.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)
}
« no previous file with comments | « appengine/cmd/helloworld_mvm/backend/main.go ('k') | appengine/cmd/logdog_coordinator/backend/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698