Chromium Code Reviews| 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) |
|
Vadim Sh.
2017/04/20 00:12:46
this thing has mentions of datastore and task queu
|
| + 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) { |