Use concrete Item rather than an interface. Removes unnecessary dupe structs
This commit is contained in:
@@ -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),
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user