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 {
|
func (b *Bitcask) Put(key string, value []byte) error {
|
||||||
if len(key) > b.config.MaxKeySize {
|
if len(key) > b.config.maxKeySize {
|
||||||
return ErrKeyTooLarge
|
return ErrKeyTooLarge
|
||||||
}
|
}
|
||||||
if len(value) > b.config.MaxValueSize {
|
if len(value) > b.config.maxValueSize {
|
||||||
return ErrValueTooLarge
|
return ErrValueTooLarge
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,7 +284,7 @@ func Merge(path string, force bool) error {
|
|||||||
return nil
|
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 {
|
if err := os.MkdirAll(path, 0755); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
38
options.go
38
options.go
@ -1,47 +1,53 @@
|
|||||||
package bitcask
|
package bitcask
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// DefaultMaxDatafileSize is the default maximum datafile size in bytes
|
||||||
DefaultMaxDatafileSize = 1 << 20 // 1MB
|
DefaultMaxDatafileSize = 1 << 20 // 1MB
|
||||||
|
|
||||||
|
// DefaultMaxKeySize is the default maximum key size in bytes
|
||||||
DefaultMaxKeySize = 64 // 64 bytes
|
DefaultMaxKeySize = 64 // 64 bytes
|
||||||
|
|
||||||
|
// DefaultMaxValueSize is the default value size in bytes
|
||||||
DefaultMaxValueSize = 1 << 16 // 65KB
|
DefaultMaxValueSize = 1 << 16 // 65KB
|
||||||
)
|
)
|
||||||
|
|
||||||
// Option ...
|
// Option is a function that takes a config struct and modifies it
|
||||||
type Option option
|
type Option func(*config) error
|
||||||
|
|
||||||
type option func(*config) error
|
|
||||||
|
|
||||||
type config struct {
|
type config struct {
|
||||||
MaxDatafileSize int
|
maxDatafileSize int
|
||||||
MaxKeySize int
|
maxKeySize int
|
||||||
MaxValueSize int
|
maxValueSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
func newDefaultConfig() *config {
|
func newDefaultConfig() *config {
|
||||||
return &config{
|
return &config{
|
||||||
MaxDatafileSize: DefaultMaxDatafileSize,
|
maxDatafileSize: DefaultMaxDatafileSize,
|
||||||
MaxKeySize: DefaultMaxKeySize,
|
maxKeySize: DefaultMaxKeySize,
|
||||||
MaxValueSize: DefaultMaxValueSize,
|
maxValueSize: DefaultMaxValueSize,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMaxDatafileSize(size int) option {
|
// WithMaxDatafileSize sets the maximum datafile size option
|
||||||
|
func WithMaxDatafileSize(size int) Option {
|
||||||
return func(cfg *config) error {
|
return func(cfg *config) error {
|
||||||
cfg.MaxDatafileSize = size
|
cfg.maxDatafileSize = size
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMaxKeySize(size int) option {
|
// WithMaxKeySize sets the maximum key size option
|
||||||
|
func WithMaxKeySize(size int) Option {
|
||||||
return func(cfg *config) error {
|
return func(cfg *config) error {
|
||||||
cfg.MaxKeySize = size
|
cfg.maxKeySize = size
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func WithMaxValueSize(size int) option {
|
// WithMaxValueSize sets the maximum value size option
|
||||||
|
func WithMaxValueSize(size int) Option {
|
||||||
return func(cfg *config) error {
|
return func(cfg *config) error {
|
||||||
cfg.MaxValueSize = size
|
cfg.maxValueSize = size
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user