0d2440649a
Add ReadOnly function that returns Option that enables read-only mode in DB. RO mode can be used by processes that won't modify the DB in order to not acquire write flock. Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
36 lines
578 B
Go
36 lines
578 B
Go
package locodebolt
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"go.etcd.io/bbolt"
|
|
)
|
|
|
|
// Option sets an optional parameter of DB.
|
|
type Option func(*options)
|
|
|
|
type options struct {
|
|
mode os.FileMode
|
|
|
|
boltOpts *bbolt.Options
|
|
}
|
|
|
|
func defaultOpts() *options {
|
|
return &options{
|
|
mode: os.ModePerm, // 0777
|
|
boltOpts: &bbolt.Options{
|
|
Timeout: 3 * time.Second,
|
|
},
|
|
}
|
|
}
|
|
|
|
// ReadOnly enables read-only mode of the DB.
|
|
//
|
|
// Do not call DB.Put method on instances with
|
|
// this option: the behavior is undefined.
|
|
func ReadOnly() Option {
|
|
return func(o *options) {
|
|
o.boltOpts.ReadOnly = true
|
|
}
|
|
}
|