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

Side by Side Diff: appengine/logdog/coordinator/config/middleware.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 config 5 package config
6 6
7 import ( 7 import (
8 "net/http" 8 "net/http"
9 9
10 "github.com/julienschmidt/httprouter"
11 log "github.com/luci/luci-go/common/logging" 10 log "github.com/luci/luci-go/common/logging"
12 » "github.com/luci/luci-go/server/middleware" 11 » "github.com/luci/luci-go/server/router"
13 » "golang.org/x/net/context"
14 ) 12 )
15 13
16 // WithConfig is a middleware.Handler that installs the LogDog Coordinator 14 // WithConfig is a middleware.Handler that installs the LogDog Coordinator
17 // configuration into the Context. 15 // configuration into the Context.
18 func WithConfig(h middleware.Handler) middleware.Handler { 16 func WithConfig() router.Handler {
19 » return func(c context.Context, rw http.ResponseWriter, r *http.Request, params httprouter.Params) { 17 » return func(c *router.Context) {
20 » » if err := UseConfig(&c); err != nil { 18 » » if err := UseConfig(&c.Context); err != nil {
21 » » » log.WithError(err).Errorf(c, "Failed to install service configuration.") 19 » » » log.WithError(err).Errorf(c.Context, "Failed to install service configuration.")
22 20 » » » c.Writer.WriteHeader(http.StatusInternalServerError)
23 » » » rw.WriteHeader(http.StatusInternalServerError) 21 » » » c.Abort()
24 » » » return
25 } 22 }
26 h(c, rw, r, params)
27 } 23 }
28 } 24 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698