-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
57 lines (49 loc) · 1.68 KB
/
config.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
49
50
51
52
53
54
55
56
57
package bitcaspy
import "time"
const (
defaultSyncInterval = time.Minute * 1
defaultCompactInterval = time.Hour * 6
defaultFileSizeInterval = time.Minute * 1
defaultMaxActiveFileSize = int64(1 << 32) // 4GB.
)
// Options represents configuration options for managing a datastore.
type Options struct {
debug bool // Enable debug logging.
dir string // Path for storing data files.
readOnly bool // Whether this datastore should be opened in a read-only mode. Only one process at a time can open it in R-W mode.
alwaysFSync bool // Should flush filesystem buffer after every right.
syncInterval *time.Duration // Interval to sync the active file on disk.
compactInterval time.Duration // Interval to compact old files.
checkFileSizeInterval time.Duration // Interval to check the file size of the active DB.
maxActiveFileSize int64 // Max size of active file in bytes. On exceeding this size it's rotated.
}
func DefaultOptions() *Options {
return &Options{
debug: false,
dir: ".",
readOnly: false,
alwaysFSync: false,
maxActiveFileSize: defaultMaxActiveFileSize,
compactInterval: defaultCompactInterval,
checkFileSizeInterval: defaultFileSizeInterval,
}
}
type Config func(*Options) error
func WithDebug() Config {
return func(o *Options) error {
o.debug = true
return nil
}
}
func WithAlwaysSync() Config {
return func(o *Options) error {
o.alwaysFSync = true
return nil
}
}
func WithReadOnly() Config {
return func (o *Options) error {
o.readOnly = true
return nil
}
}