From a3b1e451bb54927e92b925b7e571894beea85059 Mon Sep 17 00:00:00 2001 From: siddontang Date: Wed, 27 Aug 2014 15:37:42 +0800 Subject: [PATCH] remove json configuration support --- README.md | 2 +- config/config.go | 42 +++++++++++++++++++----------------------- config/config.json | 22 ---------------------- config/config_test.go | 9 --------- 4 files changed, 20 insertions(+), 55 deletions(-) delete mode 100644 config/config.json diff --git a/README.md b/README.md index 347b989..4524884 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/config/config.go b/config/config.go index e956a02..48a45f7 100644 --- a/config/config.go +++ b/config/config.go @@ -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 diff --git a/config/config.json b/config/config.json deleted file mode 100644 index 2710e0a..0000000 --- a/config/config.json +++ /dev/null @@ -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" : "" -} \ No newline at end of file diff --git a/config/config_test.go b/config/config_test.go index 943c513..218ba0f 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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") - } }