ledisdb/server/config.go

34 lines
508 B
Go
Raw Normal View History

package server
2014-05-02 13:08:20 +04:00
import (
"encoding/json"
"github.com/siddontang/ledisdb/ledis"
2014-05-02 13:08:20 +04:00
"io/ioutil"
)
type Config struct {
Addr string `json:"addr"`
DB ledis.DBConfig `json:"db"`
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)
}