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

Unified Diff: impl/cloud/context.go

Issue 2513253002: impl/cloud: Add support for "memcached" memcache. (Closed)
Patch Set: Add test for key hasing. Created 4 years, 1 month 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/cloud/datastore_test.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 f7525e439f0c62e9eefdab9155ecb83899863360..a4b19ea6990e1adbece421ee9dc7bafed5d184c6 100644
--- a/impl/cloud/context.go
+++ b/impl/cloud/context.go
@@ -5,26 +5,69 @@
package cloud
import (
+ "github.com/luci/gae/impl/dummy"
+ ds "github.com/luci/gae/service/datastore"
+ "github.com/luci/gae/service/mail"
+ mc "github.com/luci/gae/service/memcache"
+ "github.com/luci/gae/service/module"
+ "github.com/luci/gae/service/taskqueue"
+ "github.com/luci/gae/service/user"
+
"cloud.google.com/go/datastore"
+ "github.com/bradfitz/gomemcache/memcache"
"golang.org/x/net/context"
)
-// Use installs the cloud services implementation into the supplied Context.
-//
-// This includes:
-// - github.com/luci/gae/service/info
-// - github.com/luci/gae/service/datastore
+// Config is a full-stack cloud service configuration. A user can selectively
+// populate its fields, and services for the populated fields will be installed
+// in the Context and available.
//
-// This is built around the ability to use cloud datastore.
-func Use(c context.Context, client *datastore.Client) context.Context {
- return UseDS(useInfo(c), client)
+// Because the "impl/cloud" service collection is a composite set of cloud
+// services, the user can choose services based on their configuration.
+type Config struct {
+ // DS is the cloud datastore client. If populated, the datastore service will
+ // be installed.
+ DS *datastore.Client
+
+ // MC is the memcache service client. If populated, the memcache service will
+ // be installed.
+ MC *memcache.Client
}
-// UseDS installs the cloud datastore implementation into the supplied Context.
-func UseDS(c context.Context, client *datastore.Client) context.Context {
- cds := cloudDatastore{
- client: client,
+// Use installs the Config into the supplied Context. Services will be installed
+// based on the fields that are populated in Config.
+//
+// Any services that are missing will have "impl/dummy" stubs installed. These
+// stubs will panic if called.
+func (cfg Config) Use(c context.Context) context.Context {
+ // Dummy services that we don't support.
+ c = mail.Set(c, dummy.Mail())
+ c = module.Set(c, dummy.Module())
+ c = taskqueue.SetRaw(c, dummy.TaskQueue())
+ c = user.Set(c, dummy.User())
+
+ c = useInfo(c)
+
+ // datastore service
+ if cfg.DS != nil {
+ cds := cloudDatastore{
+ client: cfg.DS,
+ }
+ c = cds.use(c)
+ } else {
+ c = ds.SetRaw(c, dummy.Datastore())
+ }
+
+ // memcache service
+ if cfg.MC != nil {
+ mc := memcacheClient{
+ client: cfg.MC,
+ }
+ c = mc.use(c)
+ } else {
+ c = mc.SetRaw(c, dummy.Memcache())
}
- return cds.use(c)
+
+ return c
}
« no previous file with comments | « no previous file | impl/cloud/datastore_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698