Merge pull request #65 from shunfei/fix/etcd-json-conf

Fix/etcd json conf
pull/66/merge
Doflatango 2018-02-27 18:05:58 +08:00 committed by GitHub
commit 6c8952270a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -22,7 +22,7 @@ type Client struct {
}
func NewClient(cfg *conf.Conf) (c *Client, err error) {
cli, err := client.New(cfg.Etcd)
cli, err := client.New(cfg.Etcd.Copy())
if err != nil {
return
}

View File

@ -63,7 +63,7 @@ type Conf struct {
// 默认 300
LockTtl int64
Etcd client.Config
Etcd *etcdConfig
Mgo *db.Config
Web *webConfig
Mail *MailConf
@ -71,6 +71,19 @@ type Conf struct {
Security *Security
}
type etcdConfig struct {
Endpoints []string
Username string
Password string
DialTimeout int64 // 单位秒
conf client.Config
}
func (e *etcdConfig) Copy() client.Config {
return e.conf
}
type webConfig struct {
BindAddr string
Auth struct {
@ -131,8 +144,12 @@ func (c *Conf) parse() error {
}
if c.Etcd.DialTimeout > 0 {
c.Etcd.DialTimeout *= time.Second
c.Etcd.conf.DialTimeout = time.Duration(c.Etcd.DialTimeout) * time.Second
}
c.Etcd.conf.Username = c.Etcd.Username
c.Etcd.conf.Password = c.Etcd.Password
c.Etcd.conf.Endpoints = c.Etcd.Endpoints
if c.Ttl <= 0 {
c.Ttl = 10
}