ledisdb/server/config.go

66 lines
1.3 KiB
Go
Raw Normal View History

package server
2014-05-02 13:08:20 +04:00
import (
"encoding/json"
2014-07-23 04:30:00 +04:00
"github.com/siddontang/copier"
"github.com/siddontang/ledisdb/ledis"
2014-05-02 13:08:20 +04:00
"io/ioutil"
)
type Config struct {
Addr string `json:"addr"`
2014-06-06 07:25:13 +04:00
DataDir string `json:"data_dir"`
DB struct {
Compression bool `json:"compression"`
BlockSize int `json:"block_size"`
WriteBufferSize int `json:"write_buffer_size"`
CacheSize int `json:"cache_size"`
MaxOpenFiles int `json:"max_open_files"`
} `json:"db"`
BinLog struct {
Use bool `json:"use"`
MaxFileSize int `json:"max_file_size"`
MaxFileNum int `json:"max_file_num"`
} `json:"binlog"`
2014-06-06 07:25:13 +04:00
//set slaveof to enable replication from master
//empty, no replication
SlaveOf string `json:"slaveof"`
2014-06-11 12:48:11 +04:00
AccessLog string `json:"access_log"`
2014-05-02 13:08:20 +04:00
}
func NewConfig(data json.RawMessage) (*Config, error) {
c := new(Config)
err := json.Unmarshal(data, c)
if err != nil {
return nil, err
}
return c, nil
}
func NewConfigWithFile(fileName string) (*Config, error) {
data, err := ioutil.ReadFile(fileName)
if err != nil {
return nil, err
}
return NewConfig(data)
}
2014-07-23 04:30:00 +04:00
func (cfg *Config) NewLedisConfig() *ledis.Config {
c := new(ledis.Config)
c.DataDir = cfg.DataDir
copier.Copy(&c.DB, &cfg.DB)
copier.Copy(&c.BinLog, &cfg.BinLog)
return c
}