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

Unified Diff: impl/cloud/context.go

Issue 2829903002: Add UseFlex(c) for the cloud implementation. (Closed)
Patch Set: UseFlex Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | impl/memory/context.go » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/cloud/context.go
diff --git a/impl/cloud/context.go b/impl/cloud/context.go
index bd8fa8e1ad82fc977fc6f2109529acf327c4bb8f..9946fa57551378a8c6d4a065b69c05b28b5e5bd2 100644
--- a/impl/cloud/context.go
+++ b/impl/cloud/context.go
@@ -5,7 +5,10 @@
package cloud
import (
+ "fmt"
+
"github.com/luci/gae/impl/dummy"
+ "github.com/luci/gae/impl/memory"
ds "github.com/luci/gae/service/datastore"
"github.com/luci/gae/service/mail"
mc "github.com/luci/gae/service/memcache"
@@ -13,6 +16,7 @@ import (
"github.com/luci/gae/service/taskqueue"
"github.com/luci/gae/service/user"
+ "cloud.google.com/go/compute/metadata"
"cloud.google.com/go/datastore"
"github.com/bradfitz/gomemcache/memcache"
@@ -51,7 +55,10 @@ func (cfg Config) Use(c context.Context) context.Context {
// datastore service
if cfg.DS != nil {
- c = UseDatastore(c, cfg.DS)
+ cds := cloudDatastore{
+ client: cfg.DS,
+ }
+ c = cds.use(c)
} else {
c = ds.SetRaw(c, dummy.Datastore())
}
@@ -69,8 +76,23 @@ func (cfg Config) Use(c context.Context) context.Context {
return c
}
-// UseDatastore installs a datastore implementation into the context.
-func UseDatastore(c context.Context, client *datastore.Client) context.Context {
+// UseFlex installs a set of cloud services into the context with services
+// supported by AppEngine Flex, including:
+// * Info
+// * Datastore
+func UseFlex(c context.Context) context.Context {
+ // Flex is on GCE, so we can get the project ID from the metadata server.
+ project, err := metadata.Get("project/project-id")
+ if err != nil {
+ panic(fmt.Errorf("could not get project ID, not on GCE? %s", err.Error()))
+ }
+ // Use the memory implementation of Info.
+ c = memory.UseInfo(c, project)
+ // Create a datastore client.
+ client, err := datastore.NewClient(c, project)
+ if err != nil {
+ panic(err)
+ }
cds := cloudDatastore{
client: client,
}
« no previous file with comments | « no previous file | impl/memory/context.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698