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