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

Side by Side Diff: filters/count/mc.go

Issue 1243323002: Refactor a bit. (Closed) Base URL: https://github.com/luci/gae.git@master
Patch Set: fix golint Created 5 years, 5 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 | « filters/count/gi.go ('k') | filters/count/rds.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 count 5 package count
6 6
7 import ( 7 import (
8 "golang.org/x/net/context" 8 "golang.org/x/net/context"
9 9
10 » "github.com/luci/gae" 10 » mc "github.com/luci/gae/service/memcache"
11 ) 11 )
12 12
13 // MCCounter is the counter object for the Memcache service. 13 // MCCounter is the counter object for the Memcache service.
14 type MCCounter struct { 14 type MCCounter struct {
15 NewItem Entry 15 NewItem Entry
16 Add Entry 16 Add Entry
17 Set Entry 17 Set Entry
18 Get Entry 18 Get Entry
19 Delete Entry 19 Delete Entry
20 CompareAndSwap Entry 20 CompareAndSwap Entry
21 AddMulti Entry 21 AddMulti Entry
22 SetMulti Entry 22 SetMulti Entry
23 GetMulti Entry 23 GetMulti Entry
24 DeleteMulti Entry 24 DeleteMulti Entry
25 CompareAndSwapMulti Entry 25 CompareAndSwapMulti Entry
26 Increment Entry 26 Increment Entry
27 IncrementExisting Entry 27 IncrementExisting Entry
28 Flush Entry 28 Flush Entry
29 Stats Entry 29 Stats Entry
30 } 30 }
31 31
32 type mcCounter struct { 32 type mcCounter struct {
33 c *MCCounter 33 c *MCCounter
34 34
35 » mc gae.Memcache 35 » mc mc.Interface
36 } 36 }
37 37
38 var _ gae.Memcache = (*mcCounter)(nil) 38 var _ mc.Interface = (*mcCounter)(nil)
39 39
40 func (m *mcCounter) NewItem(key string) gae.MCItem { 40 func (m *mcCounter) NewItem(key string) mc.Item {
41 m.c.NewItem.up() 41 m.c.NewItem.up()
42 return m.mc.NewItem(key) 42 return m.mc.NewItem(key)
43 } 43 }
44 44
45 func (m *mcCounter) Get(key string) (gae.MCItem, error) { 45 func (m *mcCounter) Get(key string) (mc.Item, error) {
46 ret, err := m.mc.Get(key) 46 ret, err := m.mc.Get(key)
47 return ret, m.c.Get.up(err) 47 return ret, m.c.Get.up(err)
48 } 48 }
49 49
50 func (m *mcCounter) GetMulti(keys []string) (map[string]gae.MCItem, error) { 50 func (m *mcCounter) GetMulti(keys []string) (map[string]mc.Item, error) {
51 ret, err := m.mc.GetMulti(keys) 51 ret, err := m.mc.GetMulti(keys)
52 return ret, m.c.GetMulti.up(err) 52 return ret, m.c.GetMulti.up(err)
53 } 53 }
54 54
55 func (m *mcCounter) Add(item gae.MCItem) error { return m.c.Add.up(m.mc.Add(item )) } 55 func (m *mcCounter) Add(item mc.Item) error { return m.c.Add.up(m.mc.Add(item)) }
56 func (m *mcCounter) Set(item gae.MCItem) error { return m.c.Set.up(m.mc.Set(item )) } 56 func (m *mcCounter) Set(item mc.Item) error { return m.c.Set.up(m.mc.Set(item)) }
57 func (m *mcCounter) Delete(key string) error { return m.c.Delete.up(m.mc.Delet e(key)) } 57 func (m *mcCounter) Delete(key string) error { return m.c.Delete.up(m.mc.Delete( key)) }
58 func (m *mcCounter) CompareAndSwap(item gae.MCItem) error { 58 func (m *mcCounter) CompareAndSwap(item mc.Item) error {
59 return m.c.CompareAndSwap.up(m.mc.CompareAndSwap(item)) 59 return m.c.CompareAndSwap.up(m.mc.CompareAndSwap(item))
60 } 60 }
61 func (m *mcCounter) AddMulti(items []gae.MCItem) error { return m.c.AddMulti.up( m.mc.AddMulti(items)) } 61 func (m *mcCounter) AddMulti(items []mc.Item) error { return m.c.AddMulti.up(m.m c.AddMulti(items)) }
62 func (m *mcCounter) SetMulti(items []gae.MCItem) error { return m.c.SetMulti.up( m.mc.SetMulti(items)) } 62 func (m *mcCounter) SetMulti(items []mc.Item) error { return m.c.SetMulti.up(m.m c.SetMulti(items)) }
63 func (m *mcCounter) DeleteMulti(keys []string) error { 63 func (m *mcCounter) DeleteMulti(keys []string) error {
64 return m.c.DeleteMulti.up(m.mc.DeleteMulti(keys)) 64 return m.c.DeleteMulti.up(m.mc.DeleteMulti(keys))
65 } 65 }
66 func (m *mcCounter) Flush() error { return m.c.Flush.up(m.mc.Flush()) } 66 func (m *mcCounter) Flush() error { return m.c.Flush.up(m.mc.Flush()) }
67 67
68 func (m *mcCounter) CompareAndSwapMulti(items []gae.MCItem) error { 68 func (m *mcCounter) CompareAndSwapMulti(items []mc.Item) error {
69 return m.c.CompareAndSwapMulti.up(m.mc.CompareAndSwapMulti(items)) 69 return m.c.CompareAndSwapMulti.up(m.mc.CompareAndSwapMulti(items))
70 } 70 }
71 71
72 func (m *mcCounter) Increment(key string, delta int64, initialValue uint64) (new Value uint64, err error) { 72 func (m *mcCounter) Increment(key string, delta int64, initialValue uint64) (new Value uint64, err error) {
73 ret, err := m.mc.Increment(key, delta, initialValue) 73 ret, err := m.mc.Increment(key, delta, initialValue)
74 return ret, m.c.Increment.up(err) 74 return ret, m.c.Increment.up(err)
75 } 75 }
76 76
77 func (m *mcCounter) IncrementExisting(key string, delta int64) (newValue uint64, err error) { 77 func (m *mcCounter) IncrementExisting(key string, delta int64) (newValue uint64, err error) {
78 ret, err := m.mc.IncrementExisting(key, delta) 78 ret, err := m.mc.IncrementExisting(key, delta)
79 return ret, m.c.IncrementExisting.up(err) 79 return ret, m.c.IncrementExisting.up(err)
80 } 80 }
81 81
82 func (m *mcCounter) Stats() (*gae.MCStatistics, error) { 82 func (m *mcCounter) Stats() (*mc.Statistics, error) {
83 ret, err := m.mc.Stats() 83 ret, err := m.mc.Stats()
84 return ret, m.c.Stats.up(err) 84 return ret, m.c.Stats.up(err)
85 } 85 }
86 86
87 // FilterMC installs a counter Memcache filter in the context. 87 // FilterMC installs a counter Memcache filter in the context.
88 func FilterMC(c context.Context) (context.Context, *MCCounter) { 88 func FilterMC(c context.Context) (context.Context, *MCCounter) {
89 state := &MCCounter{} 89 state := &MCCounter{}
90 » return gae.AddMCFilters(c, func(ic context.Context, mc gae.Memcache) gae .Memcache { 90 » return mc.AddFilters(c, func(ic context.Context, mc mc.Interface) mc.Int erface {
91 return &mcCounter{state, mc} 91 return &mcCounter{state, mc}
92 }), state 92 }), state
93 } 93 }
OLDNEW
« no previous file with comments | « filters/count/gi.go ('k') | filters/count/rds.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698