remove json configuration support

This commit is contained in:
siddontang 2014-08-27 15:37:42 +08:00
parent 4b97437298
commit a3b1e451bb
4 changed files with 20 additions and 55 deletions

View File

@ -95,7 +95,7 @@ Choosing a store database to use is very simple, you have two ways:
## 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.

View File

@ -1,7 +1,6 @@
package config
import (
"encoding/json"
"github.com/BurntSushi/toml"
"io/ioutil"
)
@ -26,41 +25,41 @@ const (
)
type LevelDBConfig struct {
Compression bool `toml:"compression" json:"compression"`
BlockSize int `toml:"block_size" json:"block_size"`
WriteBufferSize int `toml:"write_buffer_size" json:"write_buffer_size"`
CacheSize int `toml:"cache_size" json:"cache_size"`
MaxOpenFiles int `toml:"max_open_files" json:"max_open_files"`
Compression bool `toml:"compression"`
BlockSize int `toml:"block_size"`
WriteBufferSize int `toml:"write_buffer_size"`
CacheSize int `toml:"cache_size"`
MaxOpenFiles int `toml:"max_open_files"`
}
type LMDBConfig struct {
MapSize int `toml:"map_size" json:"map_size"`
NoSync bool `toml:"nosync" json:"nosync"`
MapSize int `toml:"map_size"`
NoSync bool `toml:"nosync"`
}
type BinLogConfig struct {
MaxFileSize int `toml:"max_file_size" json:"max_file_size"`
MaxFileNum int `toml:"max_file_num" json:"max_file_num"`
MaxFileSize int `toml:"max_file_size"`
MaxFileNum int `toml:"max_file_num"`
}
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) {
@ -77,10 +76,7 @@ func NewConfigWithData(data []byte) (*Config, error) {
_, err := toml.Decode(string(data), cfg)
if err != nil {
//try json
if err = json.Unmarshal(data, cfg); err != nil {
return nil, err
}
return nil, err
}
return cfg, nil

View File

@ -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" : ""
}

View File

@ -28,13 +28,4 @@ func TestConfig(t *testing.T) {
if !reflect.DeepEqual(dstCfg, cfg) {
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")
}
}