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

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: 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 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.
21 func base(h middleware.Handler) httprouter.Handle {
22 return gaemiddleware.BaseProd(h)
23 }
24
25 //// Routes. 18 //// Routes.
26 19
27 func main() { 20 func main() {
28 » router := httprouter.New() 21 » r := router.New()
29 » gaemiddleware.InstallHandlers(router, base) 22 » basemw := gaemiddleware.BaseProd()
30 » router.GET("/hi", base(sayHi)) 23
31 » http.DefaultServeMux.Handle("/", router) 24 » gaemiddleware.InstallHandlers(r, basemw)
25 » r.GET("/hi", basemw, sayHi)
26 » http.DefaultServeMux.Handle("/", r)
32 27
33 appengine.Main() 28 appengine.Main()
34 } 29 }
35 30
36 //// Handlers. 31 //// Handlers.
37 32
38 func sayHi(c context.Context, w http.ResponseWriter, r *http.Request, p httprout er.Params) { 33 func sayHi(c *router.Context) {
39 » w.Write([]byte("Hi, I'm backend")) 34 » c.Writer.Write([]byte("Hi, I'm backend"))
40 } 35 }
OLDNEW
« 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