forked from TrueCloudLab/frostfs-node
58 lines
888 B
Go
58 lines
888 B
Go
|
package chainbase
|
||
|
|
||
|
import (
|
||
|
"io/fs"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"go.etcd.io/bbolt"
|
||
|
)
|
||
|
|
||
|
type Option func(*cfg)
|
||
|
|
||
|
type cfg struct {
|
||
|
path string
|
||
|
perm fs.FileMode
|
||
|
noSync bool
|
||
|
maxBatchDelay time.Duration
|
||
|
maxBatchSize int
|
||
|
}
|
||
|
|
||
|
func defaultCfg() *cfg {
|
||
|
return &cfg{
|
||
|
perm: os.ModePerm,
|
||
|
maxBatchDelay: bbolt.DefaultMaxBatchDelay,
|
||
|
maxBatchSize: bbolt.DefaultMaxBatchSize,
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithPath(path string) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.path = path
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithPerm(perm fs.FileMode) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.perm = perm
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithNoSync(noSync bool) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.noSync = noSync
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithMaxBatchDelay(maxBatchDelay time.Duration) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.maxBatchDelay = maxBatchDelay
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithMaxBatchSize(maxBatchSize int) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.maxBatchSize = maxBatchSize
|
||
|
}
|
||
|
}
|