Skip to content

Commit 37bb1a8

Browse files
authored
Revert "WIP: move file store (do not merge) (#2766)" (#2768)
This reverts commit 97275d3.
1 parent 1fe2638 commit 37bb1a8

File tree

3 files changed

+62
-64
lines changed

3 files changed

+62
-64
lines changed

store/file/file.go renamed to store/file.go

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package file
1+
package store
22

33
import (
44
"context"
@@ -10,7 +10,6 @@ import (
1010
"sync"
1111
"time"
1212

13-
"go-micro.dev/v5/store"
1413
bolt "go.etcd.io/bbolt"
1514
)
1615

@@ -27,7 +26,7 @@ var (
2726
dataBucket = "data"
2827
)
2928

30-
func NewStore(opts ...store.Option) store.Store {
29+
func NewFileStore(opts ...Option) Store {
3130
s := &fileStore{
3231
handles: make(map[string]*fileHandle),
3332
}
@@ -36,7 +35,7 @@ func NewStore(opts ...store.Option) store.Store {
3635
}
3736

3837
type fileStore struct {
39-
options store.Options
38+
options Options
4039
dir string
4140

4241
// the database handle
@@ -71,7 +70,7 @@ func (m *fileStore) delete(fd *fileHandle, key string) error {
7170
})
7271
}
7372

74-
func (m *fileStore) init(opts ...store.Option) error {
73+
func (m *fileStore) init(opts ...Option) error {
7574
for _, o := range opts {
7675
o(&m.options)
7776
}
@@ -207,7 +206,7 @@ func (m *fileStore) list(fd *fileHandle, limit, offset uint) []string {
207206
return allKeys
208207
}
209208

210-
func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
209+
func (m *fileStore) get(fd *fileHandle, k string) (*Record, error) {
211210
var value []byte
212211

213212
fd.db.View(func(tx *bolt.Tx) error {
@@ -222,7 +221,7 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
222221
})
223222

224223
if value == nil {
225-
return nil, store.ErrNotFound
224+
return nil, ErrNotFound
226225
}
227226

228227
storedRecord := &record{}
@@ -231,7 +230,7 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
231230
return nil, err
232231
}
233232

234-
newRecord := &store.Record{}
233+
newRecord := &Record{}
235234
newRecord.Key = storedRecord.Key
236235
newRecord.Value = storedRecord.Value
237236
newRecord.Metadata = make(map[string]interface{})
@@ -242,15 +241,15 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
242241

243242
if !storedRecord.ExpiresAt.IsZero() {
244243
if storedRecord.ExpiresAt.Before(time.Now()) {
245-
return nil, store.ErrNotFound
244+
return nil, ErrNotFound
246245
}
247246
newRecord.Expiry = time.Until(storedRecord.ExpiresAt)
248247
}
249248

250249
return newRecord, nil
251250
}
252251

253-
func (m *fileStore) set(fd *fileHandle, r *store.Record) error {
252+
func (m *fileStore) set(fd *fileHandle, r *Record) error {
254253
// copy the incoming record and then
255254
// convert the expiry in to a hard timestamp
256255
item := &record{}
@@ -292,12 +291,12 @@ func (f *fileStore) Close() error {
292291
return nil
293292
}
294293

295-
func (f *fileStore) Init(opts ...store.Option) error {
294+
func (f *fileStore) Init(opts ...Option) error {
296295
return f.init(opts...)
297296
}
298297

299-
func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error {
300-
var deleteOptions store.DeleteOptions
298+
func (m *fileStore) Delete(key string, opts ...DeleteOption) error {
299+
var deleteOptions DeleteOptions
301300
for _, o := range opts {
302301
o(&deleteOptions)
303302
}
@@ -310,8 +309,8 @@ func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error {
310309
return m.delete(fd, key)
311310
}
312311

313-
func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record, error) {
314-
var readOpts store.ReadOptions
312+
func (m *fileStore) Read(key string, opts ...ReadOption) ([]*Record, error) {
313+
var readOpts ReadOptions
315314
for _, o := range opts {
316315
o(&readOpts)
317316
}
@@ -343,7 +342,7 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record,
343342
keys = []string{key}
344343
}
345344

346-
var results []*store.Record
345+
var results []*Record
347346

348347
for _, k := range keys {
349348
r, err := m.get(fd, k)
@@ -356,8 +355,8 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record,
356355
return results, nil
357356
}
358357

359-
func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error {
360-
var writeOpts store.WriteOptions
358+
func (m *fileStore) Write(r *Record, opts ...WriteOption) error {
359+
var writeOpts WriteOptions
361360
for _, o := range opts {
362361
o(&writeOpts)
363362
}
@@ -369,7 +368,7 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error {
369368

370369
if len(opts) > 0 {
371370
// Copy the record before applying options, or the incoming record will be mutated
372-
newRecord := store.Record{}
371+
newRecord := Record{}
373372
newRecord.Key = r.Key
374373
newRecord.Value = r.Value
375374
newRecord.Metadata = make(map[string]interface{})
@@ -392,12 +391,12 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error {
392391
return m.set(fd, r)
393392
}
394393

395-
func (m *fileStore) Options() store.Options {
394+
func (m *fileStore) Options() Options {
396395
return m.options
397396
}
398397

399-
func (m *fileStore) List(opts ...store.ListOption) ([]string, error) {
400-
var listOptions store.ListOptions
398+
func (m *fileStore) List(opts ...ListOption) ([]string, error) {
399+
var listOptions ListOptions
401400

402401
for _, o := range opts {
403402
o(&listOptions)
@@ -440,9 +439,9 @@ func (m *fileStore) String() string {
440439

441440
type dirOptionKey struct{}
442441

443-
// DirOption is a file store store.Option to set the directory for the file
444-
func DirOption(dir string) store.Option {
445-
return func(o *store.Options) {
442+
// DirOption is a file store Option to set the directory for the file
443+
func DirOption(dir string) Option {
444+
return func(o *Options) {
446445
if o.Context == nil {
447446
o.Context = context.Background()
448447
}

0 commit comments

Comments
 (0)