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

Side by Side Diff: impl/prod/context.go

Issue 1494223002: Add API to allow you to get the non-transactional datastore or taskqueue. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix doc and naming Created 5 years 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 | « impl/memory/taskqueue_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "github.com/luci/gae/service/info"
10 "golang.org/x/net/context" 11 "golang.org/x/net/context"
11 "google.golang.org/appengine" 12 "google.golang.org/appengine"
12 ) 13 )
13 14
14 type key int 15 type key int
15 16
16 var ( 17 var (
17 » prodContextKey key 18 » prodContextKey key
18 » probeCacheKey key = 1 19 » prodContextNoTxnKey key = 1
20 » probeCacheKey key = 2
19 ) 21 )
20 22
21 // AEContext retrieves the raw "google.golang.org/appengine" compatible Context. 23 // AEContext retrieves the raw "google.golang.org/appengine" compatible Context.
22 func AEContext(c context.Context) context.Context { 24 func AEContext(c context.Context) context.Context {
23 aeCtx, _ := c.Value(prodContextKey).(context.Context) 25 aeCtx, _ := c.Value(prodContextKey).(context.Context)
24 return aeCtx 26 return aeCtx
25 } 27 }
26 28
29 // AEContextNoTxn retrieves the raw "google.golang.org/appengine" compatible
30 // Context that's not part of a transaction.
31 func AEContextNoTxn(c context.Context) context.Context {
32 aeCtx, _ := c.Value(prodContextNoTxnKey).(context.Context)
33 aeCtx, err := appengine.Namespace(aeCtx, info.Get(c).GetNamespace())
34 if err != nil {
35 panic(err)
36 }
37 return aeCtx
38 }
39
27 // Use adds production implementations for all the gae services to the 40 // Use adds production implementations for all the gae services to the
28 // context. 41 // context.
29 // 42 //
30 // The services added are: 43 // The services added are:
31 // - github.com/luci/gae/service/datastore 44 // - github.com/luci/gae/service/datastore
32 // - github.com/luci/gae/service/taskqueue 45 // - github.com/luci/gae/service/taskqueue
33 // - github.com/luci/gae/service/memcache 46 // - github.com/luci/gae/service/memcache
34 // - github.com/luci/gae/service/info 47 // - github.com/luci/gae/service/info
35 // - github.com/luci/gae/service/urlfetch 48 // - github.com/luci/gae/service/urlfetch
36 // 49 //
37 // These can be retrieved with the <service>.Get functions. 50 // These can be retrieved with the <service>.Get functions.
38 // 51 //
39 // The implementations are all backed by the real appengine SDK functionality, 52 // The implementations are all backed by the real appengine SDK functionality,
40 func Use(c context.Context, r *http.Request) context.Context { 53 func Use(c context.Context, r *http.Request) context.Context {
41 aeCtx := appengine.NewContext(r) 54 aeCtx := appengine.NewContext(r)
42 c = context.WithValue(c, prodContextKey, aeCtx) 55 c = context.WithValue(c, prodContextKey, aeCtx)
56 c = context.WithValue(c, prodContextNoTxnKey, aeCtx)
43 return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c)))))) 57 return useUser(useURLFetch(useRDS(useMC(useTQ(useGI(c))))))
44 } 58 }
OLDNEW
« no previous file with comments | « impl/memory/taskqueue_test.go ('k') | impl/prod/everything_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698