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

Side by Side Diff: memory/globalinfo.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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 unified diff | Download patch
« no previous file with comments | « memory/gkvlite_utils_test.go ('k') | memory/memcache.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « memory/gkvlite_utils_test.go ('k') | memory/memcache.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698