OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 package memory | |
6 | |
7 import ( | |
8 "golang.org/x/net/context" | |
9 | |
10 "github.com/luci/gae" | |
11 "github.com/luci/gae/dummy" | |
12 ) | |
13 | |
14 type giContextKeyType int | |
15 | |
16 var giContextKey giContextKeyType | |
17 | |
18 func curGID(c context.Context) *globalInfoData { | |
19 return c.Value(giContextKey).(*globalInfoData) | |
20 } | |
21 | |
22 // useGI adds a gae.GlobalInfo context, accessible | |
23 // by gae.GetGI(c) | |
24 func useGI(c context.Context) context.Context { | |
25 return gae.SetGIFactory(c, func(ic context.Context) gae.GlobalInfo { | |
26 return &giImpl{dummy.GI(), curGID(ic), ic} | |
27 }) | |
28 } | |
29 | |
30 // globalAppID is the 'AppID' of everythin returned from this memory | |
31 // implementation (DSKeys, GlobalInfo, etc.). There's no way to modify this | |
32 // value through the API, and there are a couple bits of code where it's hard to | |
33 // route this value through to without making the internal APIs really complex. | |
34 const globalAppID = "dev~app" | |
35 | |
36 type globalInfoData struct { | |
37 namespace string | |
38 } | |
39 | |
40 type giImpl struct { | |
41 gae.GlobalInfo | |
42 *globalInfoData | |
43 c context.Context | |
44 } | |
45 | |
46 var _ = gae.GlobalInfo((*giImpl)(nil)) | |
47 | |
48 func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) { | |
49 return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil | |
50 } | |
51 | |
52 func (gi *giImpl) AppID() string { | |
53 return globalAppID | |
54 } | |
OLD | NEW |