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

Side by Side Diff: appengine/cmd/dm/frontend/init.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 frontend 5 package frontend
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 9
10 "golang.org/x/net/context"
11
12 "github.com/julienschmidt/httprouter"
13 "github.com/luci/luci-go/appengine/cmd/dm/deps" 10 "github.com/luci/luci-go/appengine/cmd/dm/deps"
14 "github.com/luci/luci-go/appengine/gaeconfig" 11 "github.com/luci/luci-go/appengine/gaeconfig"
15 "github.com/luci/luci-go/appengine/gaemiddleware" 12 "github.com/luci/luci-go/appengine/gaemiddleware"
16 "github.com/luci/luci-go/appengine/tumble" 13 "github.com/luci/luci-go/appengine/tumble"
17 "github.com/luci/luci-go/common/config" 14 "github.com/luci/luci-go/common/config"
18 "github.com/luci/luci-go/common/logging" 15 "github.com/luci/luci-go/common/logging"
19 "github.com/luci/luci-go/server/discovery" 16 "github.com/luci/luci-go/server/discovery"
20 "github.com/luci/luci-go/server/middleware"
21 "github.com/luci/luci-go/server/prpc" 17 "github.com/luci/luci-go/server/prpc"
18 "github.com/luci/luci-go/server/router"
22 ) 19 )
23 20
24 func base(h middleware.Handler) httprouter.Handle { 21 func base() []router.Handler {
25 » newH := func(c context.Context, rw http.ResponseWriter, r *http.Request, p httprouter.Params) { 22 » return append(
26 » » cfg, err := gaeconfig.New(c) 23 » » gaemiddleware.BaseProd(),
27 » » switch err { 24 » » func(c *router.Context) {
28 » » case nil: 25 » » » cfg, err := gaeconfig.New(c.Context)
29 » » » c = config.Set(c, cfg) 26 » » » switch err {
30 » » case gaeconfig.ErrNotConfigured: 27 » » » case nil:
31 » » » logging.Warningf(c, "luci-config service url not configu red. Configure this at /admin/settings/gaeconfig.") 28 » » » » c.Context = config.Set(c.Context, cfg)
32 » » default: 29 » » » case gaeconfig.ErrNotConfigured:
33 » » » panic(err) 30 » » » » logging.Warningf(c.Context, "luci-config service url not configured. Configure this at /admin/settings/gaeconfig.")
34 » » } 31 » » » default:
35 » » h(c, rw, r, p) 32 » » » » panic(err)
36 » } 33 » » » }
37 » return gaemiddleware.BaseProd(newH) 34 » » },
35 » )
38 } 36 }
39 37
40 func init() { 38 func init() {
41 » router := httprouter.New() 39 » r := router.New()
42 tmb := tumble.Service{} 40 tmb := tumble.Service{}
43 41
44 svr := prpc.Server{} 42 svr := prpc.Server{}
45 deps.RegisterDepsServer(&svr) 43 deps.RegisterDepsServer(&svr)
46 discovery.Enable(&svr) 44 discovery.Enable(&svr)
47 45
48 » svr.InstallHandlers(router, base) 46 » svr.InstallHandlers(r, base())
49 » tmb.InstallHandlers(router) 47 » tmb.InstallHandlers(r)
50 » gaemiddleware.InstallHandlers(router, base) 48 » gaemiddleware.InstallHandlers(r, base())
51 49
52 » http.Handle("/", router) 50 » http.Handle("/", r)
53 } 51 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698