| 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)
|
| }
|
|
|