mirror of
https://github.com/gogrlx/bitcask.git
synced 2026-04-02 02:58:59 -07:00
Refactored configuration option handling. Fixes #3
This commit is contained in:
18
bitcask.go
18
bitcask.go
@@ -16,7 +16,7 @@ import (
|
||||
type Bitcask struct {
|
||||
*flock.Flock
|
||||
|
||||
opts Options
|
||||
config *config
|
||||
path string
|
||||
curr *Datafile
|
||||
keydir *Keydir
|
||||
@@ -70,11 +70,11 @@ func (b *Bitcask) Get(key string) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (b *Bitcask) Put(key string, value []byte) error {
|
||||
if len(key) > b.opts.MaxKeySize {
|
||||
return fmt.Errorf("error: key too large %d > %d", len(key), b.opts.MaxKeySize)
|
||||
if len(key) > b.config.MaxKeySize {
|
||||
return fmt.Errorf("error: key too large %d > %d", len(key), b.config.MaxKeySize)
|
||||
}
|
||||
if len(value) > b.opts.MaxValueSize {
|
||||
return fmt.Errorf("error: value too large %d > %d", len(value), b.opts.MaxValueSize)
|
||||
if len(value) > b.config.MaxValueSize {
|
||||
return fmt.Errorf("error: value too large %d > %d", len(value), b.config.MaxValueSize)
|
||||
}
|
||||
|
||||
offset, err := b.put(key, value)
|
||||
@@ -261,7 +261,7 @@ func Merge(path string, force bool) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func Open(path string, options ...func(*Bitcask) error) (*Bitcask, error) {
|
||||
func Open(path string, options ...option) (*Bitcask, error) {
|
||||
if err := os.MkdirAll(path, 0755); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -344,7 +344,7 @@ func Open(path string, options ...func(*Bitcask) error) (*Bitcask, error) {
|
||||
|
||||
bitcask := &Bitcask{
|
||||
Flock: flock.New(filepath.Join(path, "lock")),
|
||||
opts: NewDefaultOptions(),
|
||||
config: NewDefaultConfig(),
|
||||
path: path,
|
||||
curr: curr,
|
||||
keydir: keydir,
|
||||
@@ -354,8 +354,8 @@ func Open(path string, options ...func(*Bitcask) error) (*Bitcask, error) {
|
||||
maxDatafileSize: DefaultMaxDatafileSize,
|
||||
}
|
||||
|
||||
for _, option := range options {
|
||||
err = option(bitcask)
|
||||
for _, opt := range options {
|
||||
err = opt(bitcask.config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user