forked from mirror/ledisdb
remove json configuration support
This commit is contained in:
parent
4b97437298
commit
a3b1e451bb
|
@ -95,7 +95,7 @@ Choosing a store database to use is very simple, you have two ways:
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
LedisDB uses [toml](https://github.com/toml-lang/toml) as the preferred configuration format, also supports ```json``` because of some history reasons. The basic configuration ```./etc/ledis.conf``` in LedisDB source may help you.
|
LedisDB uses [toml](https://github.com/toml-lang/toml) as the configuration format. The basic configuration ```./etc/ledis.conf``` in LedisDB source may help you.
|
||||||
|
|
||||||
If you don't use a configuration, LedisDB will use the default for you.
|
If you don't use a configuration, LedisDB will use the default for you.
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
@ -26,41 +25,41 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type LevelDBConfig struct {
|
type LevelDBConfig struct {
|
||||||
Compression bool `toml:"compression" json:"compression"`
|
Compression bool `toml:"compression"`
|
||||||
BlockSize int `toml:"block_size" json:"block_size"`
|
BlockSize int `toml:"block_size"`
|
||||||
WriteBufferSize int `toml:"write_buffer_size" json:"write_buffer_size"`
|
WriteBufferSize int `toml:"write_buffer_size"`
|
||||||
CacheSize int `toml:"cache_size" json:"cache_size"`
|
CacheSize int `toml:"cache_size"`
|
||||||
MaxOpenFiles int `toml:"max_open_files" json:"max_open_files"`
|
MaxOpenFiles int `toml:"max_open_files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type LMDBConfig struct {
|
type LMDBConfig struct {
|
||||||
MapSize int `toml:"map_size" json:"map_size"`
|
MapSize int `toml:"map_size"`
|
||||||
NoSync bool `toml:"nosync" json:"nosync"`
|
NoSync bool `toml:"nosync"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type BinLogConfig struct {
|
type BinLogConfig struct {
|
||||||
MaxFileSize int `toml:"max_file_size" json:"max_file_size"`
|
MaxFileSize int `toml:"max_file_size"`
|
||||||
MaxFileNum int `toml:"max_file_num" json:"max_file_num"`
|
MaxFileNum int `toml:"max_file_num"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Addr string `toml:"addr" json:"addr"`
|
Addr string `toml:"addr"`
|
||||||
|
|
||||||
HttpAddr string `toml:"http_addr" json:"http_addr"`
|
HttpAddr string `toml:"http_addr"`
|
||||||
|
|
||||||
DataDir string `toml:"data_dir" json:"data_dir"`
|
DataDir string `toml:"data_dir"`
|
||||||
|
|
||||||
DBName string `toml:"db_name" json:"db_name"`
|
DBName string `toml:"db_name"`
|
||||||
|
|
||||||
LevelDB LevelDBConfig `toml:"leveldb" json:"leveldb"`
|
LevelDB LevelDBConfig `toml:"leveldb"`
|
||||||
|
|
||||||
LMDB LMDBConfig `toml:"lmdb" json:"lmdb"`
|
LMDB LMDBConfig `toml:"lmdb"`
|
||||||
|
|
||||||
BinLog BinLogConfig `toml:"binlog" json:"binlog"`
|
BinLog BinLogConfig `toml:"binlog"`
|
||||||
|
|
||||||
SlaveOf string `toml:"slaveof" json:"slaveof"`
|
SlaveOf string `toml:"slaveof"`
|
||||||
|
|
||||||
AccessLog string `toml:"access_log" json:"access_log"`
|
AccessLog string `toml:"access_log"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfigWithFile(fileName string) (*Config, error) {
|
func NewConfigWithFile(fileName string) (*Config, error) {
|
||||||
|
@ -77,10 +76,7 @@ func NewConfigWithData(data []byte) (*Config, error) {
|
||||||
|
|
||||||
_, err := toml.Decode(string(data), cfg)
|
_, err := toml.Decode(string(data), cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//try json
|
return nil, err
|
||||||
if err = json.Unmarshal(data, cfg); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg, nil
|
return cfg, nil
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
{
|
|
||||||
"addr": "127.0.0.1:6380",
|
|
||||||
"http_addr": "127.0.0.1:11181",
|
|
||||||
"data_dir": "/tmp/ledis_server",
|
|
||||||
|
|
||||||
"db_name" : "leveldb",
|
|
||||||
|
|
||||||
"leveldb": {
|
|
||||||
"compression": false,
|
|
||||||
"block_size": 32768,
|
|
||||||
"write_buffer_size": 67108864,
|
|
||||||
"cache_size": 524288000,
|
|
||||||
"max_open_files":1024
|
|
||||||
},
|
|
||||||
|
|
||||||
"lmdb" : {
|
|
||||||
"map_size" : 524288000,
|
|
||||||
"nosync" : true
|
|
||||||
},
|
|
||||||
|
|
||||||
"access_log" : ""
|
|
||||||
}
|
|
|
@ -28,13 +28,4 @@ func TestConfig(t *testing.T) {
|
||||||
if !reflect.DeepEqual(dstCfg, cfg) {
|
if !reflect.DeepEqual(dstCfg, cfg) {
|
||||||
t.Fatal("parse toml error")
|
t.Fatal("parse toml error")
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg, err = NewConfigWithFile("./config.json")
|
|
||||||
if err != nil {
|
|
||||||
t.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(dstCfg, cfg) {
|
|
||||||
t.Fatal("parse json error")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue