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

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

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: avoid dummy callbacks 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
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 » "golang.org/x/net/context" 8 » "fmt"
9 » "regexp"
9 10
10 "github.com/luci/gae/impl/dummy" 11 "github.com/luci/gae/impl/dummy"
11 "github.com/luci/gae/service/info" 12 "github.com/luci/gae/service/info"
13 "golang.org/x/net/context"
12 ) 14 )
13 15
14 type giContextKeyType int 16 type giContextKeyType int
15 17
16 var giContextKey giContextKeyType 18 var giContextKey giContextKeyType
17 19
20 // validNamespace matches valid namespace names.
21 var validNamespace = regexp.MustCompile(`^[0-9A-Za-z._-]{0,100}$`)
22
18 func curGID(c context.Context) *globalInfoData { 23 func curGID(c context.Context) *globalInfoData {
19 return c.Value(giContextKey).(*globalInfoData) 24 return c.Value(giContextKey).(*globalInfoData)
20 } 25 }
21 26
22 // useGI adds a gae.GlobalInfo context, accessible 27 // useGI adds a gae.GlobalInfo context, accessible
23 // by gae.GetGI(c) 28 // by gae.GetGI(c)
24 func useGI(c context.Context) context.Context { 29 func useGI(c context.Context) context.Context {
25 return info.SetFactory(c, func(ic context.Context) info.Interface { 30 return info.SetFactory(c, func(ic context.Context) info.Interface {
26 return &giImpl{dummy.Info(), curGID(ic), ic} 31 return &giImpl{dummy.Info(), curGID(ic), ic}
27 }) 32 })
(...skipping 10 matching lines...) Expand all
38 } 43 }
39 44
40 type giImpl struct { 45 type giImpl struct {
41 info.Interface 46 info.Interface
42 *globalInfoData 47 *globalInfoData
43 c context.Context 48 c context.Context
44 } 49 }
45 50
46 var _ = info.Interface((*giImpl)(nil)) 51 var _ = info.Interface((*giImpl)(nil))
47 52
53 func (gi *giImpl) GetNamespace() string {
54 return gi.namespace
55 }
56
48 func (gi *giImpl) Namespace(ns string) (ret context.Context, err error) { 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 }
49 return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil 61 return context.WithValue(gi.c, giContextKey, &globalInfoData{ns}), nil
50 } 62 }
51 63
52 func (gi *giImpl) AppID() string { 64 func (gi *giImpl) AppID() string {
53 return globalAppID 65 return globalAppID
54 } 66 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698