Move DB to Map

This commit is contained in:
Asim Aslam 2019-06-11 18:21:33 +01:00
parent 43ed8f58f0
commit f81f66c98b
2 changed files with 9 additions and 9 deletions

View File

@ -11,7 +11,7 @@ import (
lock "github.com/micro/go-micro/sync/lock/consul"
)
type syncDB struct {
type syncMap struct {
opts Options
}
@ -20,7 +20,7 @@ func ekey(k interface{}) string {
return base64.StdEncoding.EncodeToString(b)
}
func (m *syncDB) Read(key, val interface{}) error {
func (m *syncMap) Read(key, val interface{}) error {
if key == nil {
return fmt.Errorf("key is nil")
}
@ -43,7 +43,7 @@ func (m *syncDB) Read(key, val interface{}) error {
return json.Unmarshal(kval.Value, val)
}
func (m *syncDB) Write(key, val interface{}) error {
func (m *syncMap) Write(key, val interface{}) error {
if key == nil {
return fmt.Errorf("key is nil")
}
@ -69,7 +69,7 @@ func (m *syncDB) Write(key, val interface{}) error {
})
}
func (m *syncDB) Delete(key interface{}) error {
func (m *syncMap) Delete(key interface{}) error {
if key == nil {
return fmt.Errorf("key is nil")
}
@ -84,7 +84,7 @@ func (m *syncDB) Delete(key interface{}) error {
return m.opts.Data.Delete(kstr)
}
func (m *syncDB) Iterate(fn func(key, val interface{}) error) error {
func (m *syncMap) Iterate(fn func(key, val interface{}) error) error {
keyvals, err := m.opts.Data.Dump()
if err != nil {
return err
@ -137,7 +137,7 @@ func (m *syncDB) Iterate(fn func(key, val interface{}) error) error {
return nil
}
func NewDB(opts ...Option) DB {
func NewMap(opts ...Option) Map {
var options Options
for _, o := range opts {
o(&options)
@ -151,7 +151,7 @@ func NewDB(opts ...Option) DB {
options.Data = ckv.NewData()
}
return &syncDB{
return &syncMap{
opts: options,
}
}

View File

@ -9,10 +9,10 @@ import (
"github.com/micro/go-micro/sync/time"
)
// DB provides synchronized access to key-value storage.
// Map provides synchronized access to key-value storage.
// It uses the data interface and lock interface to
// provide a consistent storage mechanism.
type DB interface {
type Map interface {
// Read value with given key
Read(key, val interface{}) error
// Write value with given key