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

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

Issue 1490243004: Make appengine connection explicitly owned by impl/prod. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix other services too 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 | « no previous file | impl/prod/datastore_key.go » ('j') | impl/prod/datastore_key.go » ('J')
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 "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 // Use adds production implementations for all the gae services to the context, 14 type key int
15 // using the existing context obtained by appengine.NewContext. 15
16 // 16 var (
17 // The services added are: 17 » prodContextKey key
18 // - github.com/luci/gae/service/datastore 18 » probeCacheKey key = 1
19 // - github.com/luci/gae/service/taskqueue 19 )
20 // - github.com/luci/gae/service/memcache 20
21 // - github.com/luci/gae/service/info 21 // AEContext retrieves the raw "google.golang.org/appengine" compatible Context.
22 // - github.com/luci/gae/service/urlfetch 22 func AEContext(c context.Context) context.Context {
23 // 23 » aeCtx, _ := c.Value(prodContextKey).(context.Context)
24 // These can be retrieved with the <service>.Get functions. 24 » return aeCtx
25 //
26 // The implementations are all backed by the real appengine SDK functionality,
27 func Use(c context.Context) context.Context {
28 » return useURLFetch(useRDS(useMC(useTQ(useGI(c)))))
29 } 25 }
30 26
31 // UseRequest adds production implementations for all the gae services to the 27 // Use adds production implementations for all the gae services to the
32 // context. 28 // context.
33 // 29 //
34 // The services added are: 30 // The services added are:
35 // - github.com/luci/gae/service/datastore 31 // - github.com/luci/gae/service/datastore
36 // - github.com/luci/gae/service/taskqueue 32 // - github.com/luci/gae/service/taskqueue
37 // - github.com/luci/gae/service/memcache 33 // - github.com/luci/gae/service/memcache
38 // - github.com/luci/gae/service/info 34 // - github.com/luci/gae/service/info
39 // - github.com/luci/gae/service/urlfetch 35 // - github.com/luci/gae/service/urlfetch
40 // 36 //
41 // These can be retrieved with the <service>.Get functions. 37 // These can be retrieved with the <service>.Get functions.
42 // 38 //
43 // The implementations are all backed by the real appengine SDK functionality, 39 // The implementations are all backed by the real appengine SDK functionality,
44 func UseRequest(r *http.Request) context.Context { 40 func Use(c context.Context, r *http.Request) context.Context {
45 » return useURLFetch(useRDS(useMC(useTQ(useGI(appengine.NewContext(r)))))) 41 » aeCtx := appengine.NewContext(r)
42 » c = context.WithValue(c, prodContextKey, aeCtx)
43 » return useURLFetch(useRDS(useMC(useTQ(useGI(c)))))
46 } 44 }
OLDNEW
« no previous file with comments | « no previous file | impl/prod/datastore_key.go » ('j') | impl/prod/datastore_key.go » ('J')

Powered by Google App Engine
This is Rietveld 408576698