mirror of
https://github.com/taigrr/bitcask
synced 2025-01-18 04:03:17 -08:00
cmd/bitcask: recovery tool (#92)
* cmd/bitcask: recovery tool * refactor configuration & use it in recover tool
This commit is contained in:
committed by
James Mills
parent
f4fb4972ee
commit
0d3a9213ed
36
internal/config/config.go
Normal file
36
internal/config/config.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// Config contains the bitcask configuration parameters
|
||||
type Config struct {
|
||||
MaxDatafileSize int `json:"max_datafile_size"`
|
||||
MaxKeySize int `json:"max_key_size"`
|
||||
MaxValueSize int `json:"max_value_size"`
|
||||
Sync bool `json:"sync"`
|
||||
}
|
||||
|
||||
// Decode decodes a serialized configuration
|
||||
func Decode(path string) (*Config, error) {
|
||||
var cfg Config
|
||||
|
||||
data, err := ioutil.ReadFile(filepath.Join(path, "config.json"))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
// Encode encodes the configuration for storage
|
||||
func (c *Config) Encode() ([]byte, error) {
|
||||
return json.Marshal(c)
|
||||
}
|
||||
Reference in New Issue
Block a user