From f81f66c98b688544d007d83ae30b9c5cc7d3a834 Mon Sep 17 00:00:00 2001 From: Asim Aslam Date: Tue, 11 Jun 2019 18:21:33 +0100 Subject: [PATCH] Move DB to Map --- sync/{db.go => map.go} | 14 +++++++------- sync/sync.go | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) rename sync/{db.go => map.go} (88%) diff --git a/sync/db.go b/sync/map.go similarity index 88% rename from sync/db.go rename to sync/map.go index b5141d42..d9fcd475 100644 --- a/sync/db.go +++ b/sync/map.go @@ -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, } } diff --git a/sync/sync.go b/sync/sync.go index b27118e5..54bf26c5 100644 --- a/sync/sync.go +++ b/sync/sync.go @@ -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