1
- package file
1
+ package store
2
2
3
3
import (
4
4
"context"
@@ -10,7 +10,6 @@ import (
10
10
"sync"
11
11
"time"
12
12
13
- "go-micro.dev/v5/store"
14
13
bolt "go.etcd.io/bbolt"
15
14
)
16
15
27
26
dataBucket = "data"
28
27
)
29
28
30
- func NewStore (opts ... store. Option ) store. Store {
29
+ func NewFileStore (opts ... Option ) Store {
31
30
s := & fileStore {
32
31
handles : make (map [string ]* fileHandle ),
33
32
}
@@ -36,7 +35,7 @@ func NewStore(opts ...store.Option) store.Store {
36
35
}
37
36
38
37
type fileStore struct {
39
- options store. Options
38
+ options Options
40
39
dir string
41
40
42
41
// the database handle
@@ -71,7 +70,7 @@ func (m *fileStore) delete(fd *fileHandle, key string) error {
71
70
})
72
71
}
73
72
74
- func (m * fileStore ) init (opts ... store. Option ) error {
73
+ func (m * fileStore ) init (opts ... Option ) error {
75
74
for _ , o := range opts {
76
75
o (& m .options )
77
76
}
@@ -207,7 +206,7 @@ func (m *fileStore) list(fd *fileHandle, limit, offset uint) []string {
207
206
return allKeys
208
207
}
209
208
210
- func (m * fileStore ) get (fd * fileHandle , k string ) (* store. Record , error ) {
209
+ func (m * fileStore ) get (fd * fileHandle , k string ) (* Record , error ) {
211
210
var value []byte
212
211
213
212
fd .db .View (func (tx * bolt.Tx ) error {
@@ -222,7 +221,7 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
222
221
})
223
222
224
223
if value == nil {
225
- return nil , store . ErrNotFound
224
+ return nil , ErrNotFound
226
225
}
227
226
228
227
storedRecord := & record {}
@@ -231,7 +230,7 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
231
230
return nil , err
232
231
}
233
232
234
- newRecord := & store. Record {}
233
+ newRecord := & Record {}
235
234
newRecord .Key = storedRecord .Key
236
235
newRecord .Value = storedRecord .Value
237
236
newRecord .Metadata = make (map [string ]interface {})
@@ -242,15 +241,15 @@ func (m *fileStore) get(fd *fileHandle, k string) (*store.Record, error) {
242
241
243
242
if ! storedRecord .ExpiresAt .IsZero () {
244
243
if storedRecord .ExpiresAt .Before (time .Now ()) {
245
- return nil , store . ErrNotFound
244
+ return nil , ErrNotFound
246
245
}
247
246
newRecord .Expiry = time .Until (storedRecord .ExpiresAt )
248
247
}
249
248
250
249
return newRecord , nil
251
250
}
252
251
253
- func (m * fileStore ) set (fd * fileHandle , r * store. Record ) error {
252
+ func (m * fileStore ) set (fd * fileHandle , r * Record ) error {
254
253
// copy the incoming record and then
255
254
// convert the expiry in to a hard timestamp
256
255
item := & record {}
@@ -292,12 +291,12 @@ func (f *fileStore) Close() error {
292
291
return nil
293
292
}
294
293
295
- func (f * fileStore ) Init (opts ... store. Option ) error {
294
+ func (f * fileStore ) Init (opts ... Option ) error {
296
295
return f .init (opts ... )
297
296
}
298
297
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
301
300
for _ , o := range opts {
302
301
o (& deleteOptions )
303
302
}
@@ -310,8 +309,8 @@ func (m *fileStore) Delete(key string, opts ...store.DeleteOption) error {
310
309
return m .delete (fd , key )
311
310
}
312
311
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
315
314
for _ , o := range opts {
316
315
o (& readOpts )
317
316
}
@@ -343,7 +342,7 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record,
343
342
keys = []string {key }
344
343
}
345
344
346
- var results []* store. Record
345
+ var results []* Record
347
346
348
347
for _ , k := range keys {
349
348
r , err := m .get (fd , k )
@@ -356,8 +355,8 @@ func (m *fileStore) Read(key string, opts ...store.ReadOption) ([]*store.Record,
356
355
return results , nil
357
356
}
358
357
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
361
360
for _ , o := range opts {
362
361
o (& writeOpts )
363
362
}
@@ -369,7 +368,7 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error {
369
368
370
369
if len (opts ) > 0 {
371
370
// Copy the record before applying options, or the incoming record will be mutated
372
- newRecord := store. Record {}
371
+ newRecord := Record {}
373
372
newRecord .Key = r .Key
374
373
newRecord .Value = r .Value
375
374
newRecord .Metadata = make (map [string ]interface {})
@@ -392,12 +391,12 @@ func (m *fileStore) Write(r *store.Record, opts ...store.WriteOption) error {
392
391
return m .set (fd , r )
393
392
}
394
393
395
- func (m * fileStore ) Options () store. Options {
394
+ func (m * fileStore ) Options () Options {
396
395
return m .options
397
396
}
398
397
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
401
400
402
401
for _ , o := range opts {
403
402
o (& listOptions )
@@ -440,9 +439,9 @@ func (m *fileStore) String() string {
440
439
441
440
type dirOptionKey struct {}
442
441
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 ) {
446
445
if o .Context == nil {
447
446
o .Context = context .Background ()
448
447
}
0 commit comments