2021-02-08 18:25:17 +00:00
|
|
|
package locodebolt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
2021-02-09 15:12:09 +00:00
|
|
|
"time"
|
2021-02-08 18:25:17 +00:00
|
|
|
|
|
|
|
"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
|
2021-02-09 15:12:09 +00:00
|
|
|
boltOpts: &bbolt.Options{
|
|
|
|
Timeout: 3 * time.Second,
|
|
|
|
},
|
2021-02-08 18:25:17 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-09 15:18:29 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
}
|
|
|
|
}
|