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

Side by Side Diff: appengine/middleware/context.go

Issue 1402543003: Add initial middleware package. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/luci-go@master
Patch Set: nits Created 5 years, 2 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
« no previous file with comments | « appengine/middleware/appengine_test.go ('k') | appengine/middleware/doc.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 package middleware
6
7 import (
8 "net/http"
9
10 "github.com/julienschmidt/httprouter"
11 "github.com/luci/gae/impl/memory"
12 "github.com/luci/gae/impl/prod"
13 "github.com/luci/luci-go/appengine/gaelogger"
14 "github.com/luci/luci-go/common/logging/memlogger"
15 "golang.org/x/net/context"
16 )
17
18 // Handler is the type for all middleware handlers. Of particular note, it's the
19 // same as httprouder.Handle, except that it also has a context parameter.
20 type Handler func(context.Context, http.ResponseWriter, *http.Request, httproute r.Params)
21
22 // Base adapts a middleware-style handler to a httprouter.Handle. It passes
23 // a new, empty context to `h`.
24 func Base(h Handler) httprouter.Handle {
25 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) {
26 h(context.Background(), rw, r, p)
27 }
28 }
29
30 // BaseProd adapts a middleware-style handler to a httprouter.Handle. It passes
31 // a new context to `h` with the following services installed:
32 // * github.com/luci/gae/impl/prod (production appengine services)
33 // * github.com/luci/luci-go/appengine/gaelogger (appengine logging service)
34 func BaseProd(h Handler) httprouter.Handle {
35 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) {
36 h(gaelogger.Use(prod.UseRequest(r)), rw, r, p)
37 }
38 }
39
40 // BaseTest adapts a middleware-style handler to a httprouter.Handle. It passes
41 // a new context to `h` with the following services installed:
42 // * github.com/luci/gae/impl/memory (in-memory appengine services)
43 // * github.com/luci/luci-go/common/logging/memlogger (in-memory logging servi ce)
44 func BaseTest(h Handler) httprouter.Handle {
45 return func(rw http.ResponseWriter, r *http.Request, p httprouter.Params ) {
46 h(memlogger.Use(memory.Use(context.Background())), rw, r, p)
47 }
48 }
OLDNEW
« no previous file with comments | « appengine/middleware/appengine_test.go ('k') | appengine/middleware/doc.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698