Use concrete Item rather than an interface. Removes unnecessary dupe structs

This commit is contained in:
Asim
2015-05-23 21:25:55 +01:00
parent 74fd1fc989
commit b5dcbbe998
7 changed files with 34 additions and 121 deletions

View File

@@ -9,23 +9,10 @@ import (
type mstore struct {
sync.RWMutex
store map[string]store.Item
store map[string]*store.Item
}
type item struct {
key string
value []byte
}
func (i *item) Key() string {
return i.key
}
func (i *item) Value() []byte {
return i.value
}
func (m *mstore) Get(key string) (store.Item, error) {
func (m *mstore) Get(key string) (*store.Item, error) {
m.RLock()
v, ok := m.store[key]
m.RUnlock()
@@ -42,22 +29,15 @@ func (m *mstore) Del(key string) error {
return nil
}
func (m *mstore) Put(item store.Item) error {
func (m *mstore) Put(item *store.Item) error {
m.Lock()
m.store[item.Key()] = item
m.store[item.Key] = item
m.Unlock()
return nil
}
func (m *mstore) NewItem(key string, value []byte) store.Item {
return &item{
key: key,
value: value,
}
}
func NewStore(addrs []string, opt ...store.Option) store.Store {
return &mstore{
store: make(map[string]store.Item),
store: make(map[string]*store.Item),
}
}