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

Side by Side 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: 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 unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // Package main implements HTTP server that handles requests to backend 5 // Package main implements HTTP server that handles requests to backend
6 // module. 6 // module.
7 package main 7 package main
8 8
9 import ( 9 import (
10 "net/http" 10 "net/http"
11 11
12 "github.com/julienschmidt/httprouter"
13 "golang.org/x/net/context"
14 "google.golang.org/appengine" 12 "google.golang.org/appengine"
15 13
16 "github.com/luci/luci-go/appengine/gaemiddleware" 14 "github.com/luci/luci-go/appengine/gaemiddleware"
17 » "github.com/luci/luci-go/server/middleware" 15 » "github.com/luci/luci-go/server/router"
18 ) 16 )
19 17
20 // base is the root of the middleware chain. 18 // base is the root of the middleware chain.
21 func base(h middleware.Handler) httprouter.Handle { 19 func base() []router.Handler {
22 » return gaemiddleware.BaseProd(h) 20 » return gaemiddleware.BaseProd()
23 } 21 }
24 22
25 //// Routes. 23 //// Routes.
26 24
27 func main() { 25 func main() {
28 » router := httprouter.New() 26 » router := router.New()
29 » gaemiddleware.InstallHandlers(router, base) 27 » gaemiddleware.InstallHandlers(router, base())
30 » router.GET("/hi", base(sayHi)) 28 » router.GET("/hi", append(base(), sayHi)...)
31 http.DefaultServeMux.Handle("/", router) 29 http.DefaultServeMux.Handle("/", router)
32 30
33 appengine.Main() 31 appengine.Main()
34 } 32 }
35 33
36 //// Handlers. 34 //// Handlers.
37 35
38 func sayHi(c context.Context, w http.ResponseWriter, r *http.Request, p httprout er.Params) { 36 func sayHi(c *router.Context) {
39 » w.Write([]byte("Hi, I'm backend")) 37 » c.Writer.Write([]byte("Hi, I'm backend"))
40 } 38 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698