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

Unified Diff: appengine/cmd/helloworld_mvm/backend/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/frontend/handler.go ('k') | appengine/cmd/helloworld_mvm/frontend/main.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/cmd/helloworld_mvm/backend/main.go
diff --git a/appengine/cmd/helloworld_mvm/backend/main.go b/appengine/cmd/helloworld_mvm/backend/main.go
index 23e62c89f6ed29985ff19d978aad7e5ddbdc5219..a5d840df4c57a50a8744e07de8ae8196da76a11a 100644
--- a/appengine/cmd/helloworld_mvm/backend/main.go
+++ b/appengine/cmd/helloworld_mvm/backend/main.go
@@ -2,39 +2,34 @@
// Use of this source code is governed under the Apache License, Version 2.0
// that can be found in the LICENSE file.
// Package main implements HTTP server that handles requests to backend
// module.
package main
import (
"net/http"
- "github.com/julienschmidt/httprouter"
- "golang.org/x/net/context"
"google.golang.org/appengine"
"github.com/luci/luci-go/appengine/gaemiddleware"
- "github.com/luci/luci-go/server/middleware"
+ "github.com/luci/luci-go/server/router"
)
-// base is the root of the middleware chain.
-func base(h middleware.Handler) httprouter.Handle {
- return gaemiddleware.BaseProd(h)
-}
-
//// Routes.
func main() {
- router := httprouter.New()
- gaemiddleware.InstallHandlers(router, base)
- router.GET("/hi", base(sayHi))
- http.DefaultServeMux.Handle("/", router)
+ r := router.New()
+ basemw := gaemiddleware.BaseProd()
+
+ gaemiddleware.InstallHandlers(r, basemw)
+ r.GET("/hi", basemw, sayHi)
+ http.DefaultServeMux.Handle("/", r)
appengine.Main()
}
//// Handlers.
-func sayHi(c context.Context, w http.ResponseWriter, r *http.Request, p httprouter.Params) {
- w.Write([]byte("Hi, I'm backend"))
+func sayHi(c *router.Context) {
+ c.Writer.Write([]byte("Hi, I'm backend"))
}
« no previous file with comments | « appengine/cmd/helloworld/frontend/handler.go ('k') | appengine/cmd/helloworld_mvm/frontend/main.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698