OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package prod | 5 package prod |
6 | 6 |
7 import ( | 7 import ( |
8 "net/http" | 8 "net/http" |
9 | 9 |
10 "golang.org/x/net/context" | 10 "golang.org/x/net/context" |
11 "google.golang.org/appengine" | 11 "google.golang.org/appengine" |
12 ) | 12 ) |
13 | 13 |
14 type key int | 14 type key int |
15 | 15 |
16 var ( | 16 var ( |
17 » prodContextKey key | 17 » prodContextKey key |
18 » probeCacheKey key = 1 | 18 » prodContextNoTxKey key = 1 |
19 » probeCacheKey key = 2 | |
19 ) | 20 ) |
20 | 21 |
21 // AEContext retrieves the raw "google.golang.org/appengine" compatible Context. | 22 // AEContext retrieves the raw "google.golang.org/appengine" compatible Context. |
22 func AEContext(c context.Context) context.Context { | 23 func AEContext(c context.Context) context.Context { |
23 aeCtx, _ := c.Value(prodContextKey).(context.Context) | 24 aeCtx, _ := c.Value(prodContextKey).(context.Context) |
24 return aeCtx | 25 return aeCtx |
25 } | 26 } |
26 | 27 |
28 // AEContextNoTX retrieves the raw "google.golang.org/appengine" compatible Cont ext. | |
Vadim Sh.
2015/12/04 03:22:04
document the difference between AEContextNoTX and
| |
29 func AEContextNoTX(c context.Context) context.Context { | |
30 aeCtx, _ := c.Value(prodContextNoTxKey).(context.Context) | |
31 return aeCtx | |
32 } | |
33 | |
27 // Use adds production implementations for all the gae services to the | 34 // Use adds production implementations for all the gae services to the |
28 // context. | 35 // context. |
29 // | 36 // |
30 // The services added are: | 37 // The services added are: |
31 // - github.com/luci/gae/service/datastore | 38 // - github.com/luci/gae/service/datastore |
32 // - github.com/luci/gae/service/taskqueue | 39 // - github.com/luci/gae/service/taskqueue |
33 // - github.com/luci/gae/service/memcache | 40 // - github.com/luci/gae/service/memcache |
34 // - github.com/luci/gae/service/info | 41 // - github.com/luci/gae/service/info |
35 // - github.com/luci/gae/service/urlfetch | 42 // - github.com/luci/gae/service/urlfetch |
36 // | 43 // |
37 // These can be retrieved with the <service>.Get functions. | 44 // These can be retrieved with the <service>.Get functions. |
38 // | 45 // |
39 // The implementations are all backed by the real appengine SDK functionality, | 46 // The implementations are all backed by the real appengine SDK functionality, |
40 func Use(c context.Context, r *http.Request) context.Context { | 47 func Use(c context.Context, r *http.Request) context.Context { |
41 aeCtx := appengine.NewContext(r) | 48 aeCtx := appengine.NewContext(r) |
42 c = context.WithValue(c, prodContextKey, aeCtx) | 49 c = context.WithValue(c, prodContextKey, aeCtx) |
50 c = context.WithValue(c, prodContextNoTxKey, aeCtx) | |
43 return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c)))))) | 51 return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c)))))) |
44 } | 52 } |
OLD | NEW |