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

Unified Diff: impl/memory/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 | « impl/cloud/context.go ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: impl/memory/context.go
diff --git a/impl/memory/context.go b/impl/memory/context.go
index feddfda29bd9a3485ac4c86d9dbe2449c78f09e2..9d38ce1cd4e6f583dcb25743f3f624fd48566707 100644
--- a/impl/memory/context.go
+++ b/impl/memory/context.go
@@ -96,6 +96,30 @@ func Use(c context.Context) context.Context {
return UseWithAppID(c, "dev~app")
}
+// UseInfo adds an implementation for:
+// * github.com/luci/gae/service/info
+// The application id wil be set to 'aid', and will not be modifiable in this
+// context. If 'aid' contains a "~" character, it will be treated as the
+// fully-qualified App ID and the AppID will be the string following the "~".
+func UseInfo(c context.Context, aid string) context.Context {
+ if c.Value(&memContextKey) != nil {
+ panic(errors.New("memory.Use: called twice on the same Context"))
+ }
+
+ fqAppID := aid
+ if parts := strings.SplitN(fqAppID, "~", 2); len(parts) == 2 {
+ aid = parts[1]
+ }
+
+ memctx := newMemContext(fqAppID)
+ c = context.WithValue(c, &memContextKey, memctx)
+
+ return useGI(useGID(c, func(mod *globalInfoData) {
+ mod.appID = aid
+ mod.fqAppID = fqAppID
+ }))
+}
+
// UseWithAppID adds implementations for the following gae services to the
// context:
// * github.com/luci/gae/service/datastore
@@ -117,23 +141,9 @@ func Use(c context.Context) context.Context {
//
// Using this more than once per context.Context will cause a panic.
func UseWithAppID(c context.Context, aid string) context.Context {
- if c.Value(&memContextKey) != nil {
- panic(errors.New("memory.Use: called twice on the same Context"))
- }
c = memlogger.Use(c)
-
- fqAppID := aid
- if parts := strings.SplitN(fqAppID, "~", 2); len(parts) == 2 {
- aid = parts[1]
- }
-
- memctx := newMemContext(fqAppID)
- c = context.WithValue(c, &memContextKey, memctx)
- c = useGID(c, func(mod *globalInfoData) {
- mod.appID = aid
- mod.fqAppID = fqAppID
- })
- return useMod(useMail(useUser(useTQ(useRDS(useMC(useGI(c)))))))
+ c = UseInfo(c, aid) // Panics if UseWithAppID is called twice.
+ return useMod(useMail(useUser(useTQ(useRDS(useMC(c))))))
}
func cur(c context.Context) (*memContext, bool) {
« no previous file with comments | « impl/cloud/context.go ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698