Skip to content

Commit

Permalink
Move DB to Map
Browse files Browse the repository at this point in the history
  • Loading branch information
asim committed Jun 11, 2019
1 parent 43ed8f5 commit f81f66c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions sync/db.go → sync/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
lock "github.com/micro/go-micro/sync/lock/consul"
)

type syncDB struct {
type syncMap struct {
opts Options
}

Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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")
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -151,7 +151,7 @@ func NewDB(opts ...Option) DB {
options.Data = ckv.NewData()
}

return &syncDB{
return &syncMap{
opts: options,
}
}
4 changes: 2 additions & 2 deletions sync/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f81f66c

Please sign in to comment.