From aaee01b1a7561e1df5eb6bfdc24341459d2d277b Mon Sep 17 00:00:00 2001 From: Janos Dobronszki Date: Tue, 7 Apr 2020 15:19:45 +0200 Subject: [PATCH] Use file store by default (as opposed to memory store) (#1498) * Use file store by default (as opposed to memory store) * Default table for file store --- defaults.go | 4 ++-- store/file/file.go | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/defaults.go b/defaults.go index ca5b1e57..10408f90 100644 --- a/defaults.go +++ b/defaults.go @@ -10,7 +10,7 @@ import ( gcli "github.com/micro/go-micro/v2/client/grpc" memTrace "github.com/micro/go-micro/v2/debug/trace/memory" gsrv "github.com/micro/go-micro/v2/server/grpc" - memStore "github.com/micro/go-micro/v2/store/memory" + fileStore "github.com/micro/go-micro/v2/store/file" ) func init() { @@ -19,7 +19,7 @@ func init() { // default server server.DefaultServer = gsrv.NewServer() // default store - store.DefaultStore = memStore.NewStore() + store.DefaultStore = fileStore.NewStore() // set default trace trace.DefaultTracer = memTrace.NewTracer() } diff --git a/store/file/file.go b/store/file/file.go index 2c6b6092..cf061fd7 100644 --- a/store/file/file.go +++ b/store/file/file.go @@ -17,6 +17,16 @@ import ( "github.com/pkg/errors" ) +var ( + // DefaultDatabase is the namespace that the bbolt store + // will use if no namespace is provided. + DefaultDatabase = "micro" + // DefaultTable when none is specified + DefaultTable = "micro" + // DefaultDir is the default directory for bbolt files + DefaultDir = os.TempDir() +) + // NewStore returns a memory store func NewStore(opts ...store.Option) store.Store { s := &fileStore{ @@ -36,18 +46,17 @@ type fileStore struct { } func (m *fileStore) Init(opts ...store.Option) error { - // m.store.Flush() for _, o := range opts { o(&m.options) } if m.options.Database == "" { - m.options.Database = "default" + m.options.Database = DefaultDatabase } if m.options.Table == "" { // bbolt requires bucketname to not be empty - m.options.Table = "default" + m.options.Table = DefaultTable } - dir := filepath.Join(os.TempDir(), "micro") + dir := filepath.Join(DefaultDir, "micro") fname := m.options.Database + ".db" _ = os.Mkdir(dir, 0700) m.dir = dir