forked from abdullin/cellar
-
Notifications
You must be signed in to change notification settings - Fork 1
/
options.go
48 lines (39 loc) · 993 Bytes
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package cellar
import (
"go.uber.org/zap"
)
type Option func(db *DB) error
// WithCipher allows for customizing the read/write encryption.
func WithCipher(cipher Cipher) Option {
return func(db *DB) error {
db.cipher = cipher
return nil
}
}
func WithMetaDB(mdb MetaDB) Option {
return func(db *DB) error {
db.meta = mdb
return nil
}
}
// MockLock mocks a flock (filelock)
type MockLock struct{}
func (m MockLock) TryLock() (bool, error) { return true, nil }
func (m MockLock) Lock() error { return nil }
func (m MockLock) Unlock() error { return nil }
// WithNoFileLock is only recommending in unit tests, as it allows for concurrent writers
// (which is a big nono if you want data integrity)
func WithNoFileLock(db *DB) error {
db.fileLock = MockLock{}
return nil
}
func WithReadOnly(db *DB) error {
db.readonly = true
return nil
}
func WithLogger(logger *zap.Logger) Option {
return func(db *DB) error {
db.logger = logger
return nil
}
}