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

Unified Diff: appengine/cmd/logdog_coordinator/vmuser/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/logdog_coordinator/vmuser/main.go
diff --git a/appengine/cmd/logdog_coordinator/vmuser/main.go b/appengine/cmd/logdog_coordinator/vmuser/main.go
index b407c7e3fa25d9c919fade05b81d7504eca2c489..1a81daeccdc5b89412d5466f2fe3a8ac63993595 100644
--- a/appengine/cmd/logdog_coordinator/vmuser/main.go
+++ b/appengine/cmd/logdog_coordinator/vmuser/main.go
@@ -7,7 +7,6 @@ package main
import (
"net/http"
- "github.com/julienschmidt/httprouter"
"github.com/luci/luci-go/appengine/gaemiddleware"
"github.com/luci/luci-go/appengine/logdog/coordinator"
"github.com/luci/luci-go/appengine/logdog/coordinator/config"
@@ -21,8 +20,8 @@ import (
servicesPb "github.com/luci/luci-go/common/api/logdog_coordinator/services/v1"
log "github.com/luci/luci-go/common/logging"
"github.com/luci/luci-go/server/discovery"
- "github.com/luci/luci-go/server/middleware"
"github.com/luci/luci-go/server/prpc"
+ "github.com/luci/luci-go/server/router"
"golang.org/x/net/context"
"google.golang.org/appengine"
@@ -32,19 +31,20 @@ import (
)
// base is the root of the middleware chain.
-func base(installConfig bool) middleware.Base {
- return func(h middleware.Handler) httprouter.Handle {
- if installConfig {
- h = config.WithConfig(h)
- }
- h = coordinator.WithProdServices(h)
- return gaemiddleware.BaseProd(h)
+func base(installConfig bool) []router.Handler {
+ h := append(
+ gaemiddleware.BaseProd(),
+ coordinator.WithProdServices(),
+ )
+ if installConfig {
+ h = append(h, config.WithConfig())
}
+ return h
}
// Run installs and executes this site.
func main() {
- router := httprouter.New()
+ r := router.New()
// Setup Cloud Endpoints.
svr := prpc.Server{
@@ -57,15 +57,15 @@ func main() {
discovery.Enable(&svr)
// Standard HTTP endpoints.
- gaemiddleware.InstallHandlers(router, base(false))
- svr.InstallHandlers(router, base(true))
+ gaemiddleware.InstallHandlers(r, base(false))
+ svr.InstallHandlers(r, base(true))
// Redirect "/" to "/app/".
- router.GET("/", func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
- http.Redirect(w, r, "/app/", http.StatusFound)
+ r.GET("/", func(c *router.Context) {
+ http.Redirect(c.Writer, c.Request, "/app/", http.StatusFound)
})
- http.Handle("/", router)
+ http.Handle("/", r)
appengine.Main()
}

Powered by Google App Engine
This is Rietveld 408576698