OLD | NEW |
1 // Copyright 2015 The LUCI Authors. All rights reserved. | 1 // Copyright 2015 The LUCI Authors. All rights reserved. |
2 // Use of this source code is governed under the Apache License, Version 2.0 | 2 // Use of this source code is governed under the Apache License, Version 2.0 |
3 // that can be found in the LICENSE file. | 3 // that can be found in the LICENSE file. |
4 | 4 |
5 package memcache | 5 package memcache |
6 | 6 |
7 import ( | 7 import ( |
8 "golang.org/x/net/context" | 8 "golang.org/x/net/context" |
9 ) | 9 ) |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 | 26 |
27 // getUnfiltered gets gets the RawInterface implementation from context without | 27 // getUnfiltered gets gets the RawInterface implementation from context without |
28 // any of the filters applied. | 28 // any of the filters applied. |
29 func getUnfiltered(c context.Context) RawInterface { | 29 func getUnfiltered(c context.Context) RawInterface { |
30 if f, ok := c.Value(memcacheKey).(RawFactory); ok && f != nil { | 30 if f, ok := c.Value(memcacheKey).(RawFactory); ok && f != nil { |
31 return f(c) | 31 return f(c) |
32 } | 32 } |
33 return nil | 33 return nil |
34 } | 34 } |
35 | 35 |
36 // GetRaw gets the current memcache implementation from the context. | 36 // Raw gets the current memcache implementation from the context. |
37 func GetRaw(c context.Context) RawInterface { | 37 func Raw(c context.Context) RawInterface { |
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 ret |
46 } | 46 } |
47 | 47 |
(...skipping 22 matching lines...) Expand all Loading... |
70 func AddRawFilters(c context.Context, filts ...RawFilter) context.Context { | 70 func AddRawFilters(c context.Context, filts ...RawFilter) 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([]RawFilter, 0, len(cur)+len(filts)) | 75 newFilts := make([]RawFilter, 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, memcacheFilterKey, newFilts) | 78 return context.WithValue(c, memcacheFilterKey, newFilts) |
79 } | 79 } |
OLD | NEW |