mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
Add docs for options
This commit is contained in:
parent
34ad78efc0
commit
27eb922ba2
@ -85,10 +85,10 @@ func (b *Bitcask) Has(key string) bool {
|
||||
}
|
||||
|
||||
func (b *Bitcask) Put(key string, value []byte) error {
|
||||
if len(key) > b.config.MaxKeySize {
|
||||
if len(key) > b.config.maxKeySize {
|
||||
return ErrKeyTooLarge
|
||||
}
|
||||
if len(value) > b.config.MaxValueSize {
|
||||
if len(value) > b.config.maxValueSize {
|
||||
return ErrValueTooLarge
|
||||
}
|
||||
|
||||
@ -284,7 +284,7 @@ func Merge(path string, force bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Open(path string, options ...option) (*Bitcask, error) {
|
||||
func Open(path string, options ...Option) (*Bitcask, error) {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
42
options.go
42
options.go
@ -1,47 +1,53 @@
|
||||
package bitcask
|
||||
|
||||
const (
|
||||
// DefaultMaxDatafileSize is the default maximum datafile size in bytes
|
||||
DefaultMaxDatafileSize = 1 << 20 // 1MB
|
||||
DefaultMaxKeySize = 64 // 64 bytes
|
||||
DefaultMaxValueSize = 1 << 16 // 65KB
|
||||
|
||||
// DefaultMaxKeySize is the default maximum key size in bytes
|
||||
DefaultMaxKeySize = 64 // 64 bytes
|
||||
|
||||
// DefaultMaxValueSize is the default value size in bytes
|
||||
DefaultMaxValueSize = 1 << 16 // 65KB
|
||||
)
|
||||
|
||||
// Option ...
|
||||
type Option option
|
||||
|
||||
type option func(*config) error
|
||||
// Option is a function that takes a config struct and modifies it
|
||||
type Option func(*config) error
|
||||
|
||||
type config struct {
|
||||
MaxDatafileSize int
|
||||
MaxKeySize int
|
||||
MaxValueSize int
|
||||
maxDatafileSize int
|
||||
maxKeySize int
|
||||
maxValueSize int
|
||||
}
|
||||
|
||||
func newDefaultConfig() *config {
|
||||
return &config{
|
||||
MaxDatafileSize: DefaultMaxDatafileSize,
|
||||
MaxKeySize: DefaultMaxKeySize,
|
||||
MaxValueSize: DefaultMaxValueSize,
|
||||
maxDatafileSize: DefaultMaxDatafileSize,
|
||||
maxKeySize: DefaultMaxKeySize,
|
||||
maxValueSize: DefaultMaxValueSize,
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxDatafileSize(size int) option {
|
||||
// WithMaxDatafileSize sets the maximum datafile size option
|
||||
func WithMaxDatafileSize(size int) Option {
|
||||
return func(cfg *config) error {
|
||||
cfg.MaxDatafileSize = size
|
||||
cfg.maxDatafileSize = size
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxKeySize(size int) option {
|
||||
// WithMaxKeySize sets the maximum key size option
|
||||
func WithMaxKeySize(size int) Option {
|
||||
return func(cfg *config) error {
|
||||
cfg.MaxKeySize = size
|
||||
cfg.maxKeySize = size
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func WithMaxValueSize(size int) option {
|
||||
// WithMaxValueSize sets the maximum value size option
|
||||
func WithMaxValueSize(size int) Option {
|
||||
return func(cfg *config) error {
|
||||
cfg.MaxValueSize = size
|
||||
cfg.maxValueSize = size
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user