Skip to content

Commit

Permalink
Setting up file store in constructor and not in init which is o… (mic…
Browse files Browse the repository at this point in the history
  • Loading branch information
crufter authored Apr 7, 2020
1 parent 6aaad7d commit 038b936
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
fileStore "github.com/micro/go-micro/v2/store/file"
memoryStore "github.com/micro/go-micro/v2/store/memory"
)

func init() {
Expand All @@ -19,7 +19,7 @@ func init() {
// default server
server.DefaultServer = gsrv.NewServer()
// default store
store.DefaultStore = fileStore.NewStore()
store.DefaultStore = memoryStore.NewStore()
// set default trace
trace.DefaultTracer = memTrace.NewTracer()
}
11 changes: 8 additions & 3 deletions store/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func NewStore(opts ...store.Option) store.Store {
s := &fileStore{
options: store.Options{},
}
for _, o := range opts {
o(&s.options)
}
s.init(opts...)
return s
}

Expand All @@ -46,6 +44,10 @@ type fileStore struct {
}

func (m *fileStore) Init(opts ...store.Option) error {
return m.init(opts...)
}

func (m *fileStore) init(opts ...store.Option) error {
for _, o := range opts {
o(&m.options)
}
Expand All @@ -58,6 +60,9 @@ func (m *fileStore) Init(opts ...store.Option) error {
}
dir := filepath.Join(DefaultDir, "micro")
fname := m.options.Database + ".db"
// Ignoring this as the folder might exist.
// Reads/Writes updates will return with sensible error messages
// about the dir not existing in case this cannot create the path anyway
_ = os.Mkdir(dir, 0700)
m.dir = dir
m.fileName = fname
Expand Down

0 comments on commit 038b936

Please sign in to comment.