68 lines
1.1 KiB
Go
68 lines
1.1 KiB
Go
|
package chainbase
|
||
|
|
||
|
import (
|
||
|
"io/fs"
|
||
|
"os"
|
||
|
"time"
|
||
|
|
||
|
"git.frostfs.info/TrueCloudLab/frostfs-node/pkg/util/logger"
|
||
|
"go.etcd.io/bbolt"
|
||
|
"go.uber.org/zap"
|
||
|
)
|
||
|
|
||
|
type Option func(*cfg)
|
||
|
|
||
|
type cfg struct {
|
||
|
path string
|
||
|
perm fs.FileMode
|
||
|
noSync bool
|
||
|
maxBatchDelay time.Duration
|
||
|
maxBatchSize int
|
||
|
log *logger.Logger
|
||
|
}
|
||
|
|
||
|
func defaultCfg() *cfg {
|
||
|
return &cfg{
|
||
|
perm: os.ModePerm,
|
||
|
maxBatchDelay: bbolt.DefaultMaxBatchDelay,
|
||
|
maxBatchSize: bbolt.DefaultMaxBatchSize,
|
||
|
log: &logger.Logger{Logger: zap.L()},
|
||
|
}
|
||
|
}
|
||
|
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func WithLogger(l *logger.Logger) Option {
|
||
|
return func(c *cfg) {
|
||
|
c.log = l
|
||
|
}
|
||
|
}
|