2014-05-16 11:03:23 +04:00
|
|
|
package server
|
2014-05-02 13:08:20 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2014-05-16 11:03:23 +04:00
|
|
|
"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"`
|
|
|
|
|
|
|
|
//if you not set db path, use data_dir
|
2014-05-20 04:41:24 +04:00
|
|
|
DB ledis.Config `json:"db"`
|
2014-06-06 07:25:13 +04:00
|
|
|
|
2014-06-06 10:57:18 +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)
|
|
|
|
}
|