| 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 // 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 } |
| OLD | NEW |