2014-05-09 10:49:22 +04:00
|
|
|
package ledis
|
2014-05-02 13:08:20 +04:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
2014-05-14 12:35:49 +04:00
|
|
|
"github.com/siddontang/go-leveldb/leveldb"
|
2014-05-02 13:08:20 +04:00
|
|
|
"io/ioutil"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
|
|
|
Addr string `json:"addr"`
|
|
|
|
|
|
|
|
DB leveldb.Config `json:"leveldb"`
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|