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

Side by Side Diff: impl/memory/globalinfo.go

Issue 1281173002: Refactor: Rename some files. (Closed) Base URL: https://github.com/luci/gae.git@tweak_testable
Patch Set: Created 5 years, 4 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 | « impl/memory/datastore_test.go ('k') | impl/memory/info.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 "fmt"
9 "regexp"
10
11 "github.com/luci/gae/impl/dummy"
12 "github.com/luci/gae/service/info"
13 "golang.org/x/net/context"
14 )
15
16 type giContextKeyType int
17
18 var giContextKey giContextKeyType
19
20 // validNamespace matches valid namespace names.
21 var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
22
23 func curGID(c context.Context) *globalInfoData {
24 return c.Value(giContextKey).(*globalInfoData)
25 }
26
27 // useGI adds a gae.GlobalInfo context, accessible
28 // by gae.GetGI(c)
29 func useGI(c context.Context) context.Context {
30 return info.SetFactory(c, func(ic context.Context) info.Interface {
31 return &giImpl{dummy.Info(), curGID(ic), ic}
32 })
33 }
34
35 // globalAppID is the 'AppID' of everythin returned from this memory
36 // implementation (DSKeys, GlobalInfo, etc.). There's no way to modify this
37 // value through the API, and there are a couple bits of code where it's hard to
38 // route this value through to without making the internal APIs really complex.
39 const globalAppID = "dev~app"
40
41 type globalInfoData struct {
42 namespace string
43 }
44
45 type giImpl struct {
46 info.Interface
47 *globalInfoData
48 c context.Context
49 }
50
51 var _ = info.Interface((*giImpl)(nil))
52
53 func (gi *giImpl) GetNamespace() string {
54 return gi.namespace
55 }
56
57 func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) {
58 if !validNamespace.MatchString(ns) {
59 return nil, fmt.Errorf("appengine: namespace %q does not match / %s/", ns, validNamespace)
60 }
61 return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil
62 }
63
64 func (gi *giImpl) AppID() string {
65 return globalAppID
66 }
OLDNEW
« no previous file with comments | « impl/memory/datastore_test.go ('k') | impl/memory/info.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698