Setting up file store in constructor and not in init which is o… (#1499)
This commit is contained in:
parent
090303e1af
commit
af9214a4f9
11
file.go
11
file.go
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
}
|
||||
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user