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

Side by Side Diff: service/rawdatastore/context.go

Issue 1253263002: Make rawdatastore API safer for writing filters. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix comments 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 | « service/rawdatastore/checkfilter.go ('k') | service/rawdatastore/context_test.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 rawdatastore 5 package rawdatastore
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 ) 9 )
10 10
(...skipping 24 matching lines...) Expand all
35 35
36 // Get gets the Interface implementation from context. 36 // Get gets the Interface implementation from context.
37 func Get(c context.Context) Interface { 37 func Get(c context.Context) Interface {
38 ret := getUnfiltered(c) 38 ret := getUnfiltered(c)
39 if ret == nil { 39 if ret == nil {
40 return nil 40 return nil
41 } 41 }
42 for _, f := range getCurFilters(c) { 42 for _, f := range getCurFilters(c) {
43 ret = f(c, ret) 43 ret = f(c, ret)
44 } 44 }
45 » return ret 45 » return applyCheckFilter(c, ret)
46 } 46 }
47 47
48 // SetFactory sets the function to produce Datastore instances, as returned by 48 // SetFactory sets the function to produce Datastore instances, as returned by
49 // the Get method. 49 // the Get method.
50 func SetFactory(c context.Context, rdsf Factory) context.Context { 50 func SetFactory(c context.Context, rdsf Factory) context.Context {
51 return context.WithValue(c, rawDatastoreKey, rdsf) 51 return context.WithValue(c, rawDatastoreKey, rdsf)
52 } 52 }
53 53
54 // Set sets the current Datastore object in the context. Useful for testing with 54 // Set sets the current Datastore object in the context. Useful for testing with
55 // a quick mock. This is just a shorthand SetFactory invocation to set a factory 55 // a quick mock. This is just a shorthand SetFactory invocation to set a factory
(...skipping 14 matching lines...) Expand all
70 func AddFilters(c context.Context, filts ...Filter) context.Context { 70 func AddFilters(c context.Context, filts ...Filter) context.Context {
71 if len(filts) == 0 { 71 if len(filts) == 0 {
72 return c 72 return c
73 } 73 }
74 cur := getCurFilters(c) 74 cur := getCurFilters(c)
75 newFilts := make([]Filter, 0, len(cur)+len(filts)) 75 newFilts := make([]Filter, 0, len(cur)+len(filts))
76 newFilts = append(newFilts, getCurFilters(c)...) 76 newFilts = append(newFilts, getCurFilters(c)...)
77 newFilts = append(newFilts, filts...) 77 newFilts = append(newFilts, filts...)
78 return context.WithValue(c, rawDatastoreFilterKey, newFilts) 78 return context.WithValue(c, rawDatastoreFilterKey, newFilts)
79 } 79 }
OLDNEW
« no previous file with comments | « service/rawdatastore/checkfilter.go ('k') | service/rawdatastore/context_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698