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

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

Issue 1916463004: impl/memory: Disallow empty namespace. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/luci/gae@master
Patch Set: Remove memcache. Created 4 years, 8 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
OLDNEW
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 "fmt" 8 "fmt"
9 "regexp" 9 "regexp"
10 10
(...skipping 11 matching lines...) Expand all
22 22
23 var defaultGlobalInfoData = globalInfoData{ 23 var defaultGlobalInfoData = globalInfoData{
24 // versionID returns X.Y where Y is autogenerated by appengine, and X is 24 // versionID returns X.Y where Y is autogenerated by appengine, and X is
25 // whatever's in app.yaml. 25 // whatever's in app.yaml.
26 versionID: "testVersionID.1", 26 versionID: "testVersionID.1",
27 requestID: "test-request-id", 27 requestID: "test-request-id",
28 } 28 }
29 29
30 type globalInfoData struct { 30 type globalInfoData struct {
31 appid string 31 appid string
32 » namespace string 32 » namespace *string
33 versionID string 33 versionID string
34 requestID string 34 requestID string
35 } 35 }
36 36
37 func (gid *globalInfoData) getNamespace() (string, bool) {
38 if ns := gid.namespace; ns != nil {
39 return *ns, true
40 }
41 return "", false
42 }
43
37 func curGID(c context.Context) *globalInfoData { 44 func curGID(c context.Context) *globalInfoData {
38 if gid, ok := c.Value(giContextKey).(*globalInfoData); ok { 45 if gid, ok := c.Value(giContextKey).(*globalInfoData); ok {
39 return gid 46 return gid
40 } 47 }
41 return &defaultGlobalInfoData 48 return &defaultGlobalInfoData
42 } 49 }
43 50
44 func useGID(c context.Context, f func(mod *globalInfoData)) context.Context { 51 func useGID(c context.Context, f func(mod *globalInfoData)) context.Context {
45 cur := curGID(c) 52 cur := curGID(c)
46 if cur == nil { 53 if cur == nil {
(...skipping 14 matching lines...) Expand all
61 } 68 }
62 69
63 type giImpl struct { 70 type giImpl struct {
64 info.Interface 71 info.Interface
65 *globalInfoData 72 *globalInfoData
66 c context.Context 73 c context.Context
67 } 74 }
68 75
69 var _ = info.Interface((*giImpl)(nil)) 76 var _ = info.Interface((*giImpl)(nil))
70 77
71 func (gi *giImpl) GetNamespace() string { 78 func (gi *giImpl) GetNamespace() (string, bool) {
72 » return gi.namespace 79 » return gi.getNamespace()
73 } 80 }
74 81
75 func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) { 82 func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) {
76 if !validNamespace.MatchString(ns) { 83 if !validNamespace.MatchString(ns) {
77 return nil, fmt.Errorf("appengine: namespace %q does not match / %s/", ns, validNamespace) 84 return nil, fmt.Errorf("appengine: namespace %q does not match / %s/", ns, validNamespace)
78 } 85 }
79 86
80 return useGID(gi.c, func(mod *globalInfoData) { 87 return useGID(gi.c, func(mod *globalInfoData) {
81 » » mod.namespace = ns 88 » » mod.namespace = &ns
82 }), nil 89 }), nil
83 } 90 }
84 91
85 func (gi *giImpl) MustNamespace(ns string) context.Context { 92 func (gi *giImpl) MustNamespace(ns string) context.Context {
86 ret, err := gi.Namespace(ns) 93 ret, err := gi.Namespace(ns)
87 if err != nil { 94 if err != nil {
88 panic(err) 95 panic(err)
89 } 96 }
90 return ret 97 return ret
91 } 98 }
(...skipping 26 matching lines...) Expand all
118 return useGID(gi.c, func(mod *globalInfoData) { 125 return useGID(gi.c, func(mod *globalInfoData) {
119 mod.versionID = v 126 mod.versionID = v
120 }) 127 })
121 } 128 }
122 129
123 func (gi *giImpl) SetRequestID(v string) context.Context { 130 func (gi *giImpl) SetRequestID(v string) context.Context {
124 return useGID(gi.c, func(mod *globalInfoData) { 131 return useGID(gi.c, func(mod *globalInfoData) {
125 mod.requestID = v 132 mod.requestID = v
126 }) 133 })
127 } 134 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698