From 870fb4a88cf34c9b95c90c1bd5c6c372bf24b80b Mon Sep 17 00:00:00 2001 From: Doflatango Date: Tue, 27 Feb 2018 15:19:41 +0800 Subject: [PATCH] Fix etcd configuration json fields --- client.go | 2 +- conf/conf.go | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/client.go b/client.go index c2b30ec..f94d0dc 100644 --- a/client.go +++ b/client.go @@ -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 } diff --git a/conf/conf.go b/conf/conf.go index 06db5a7..fedf12d 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -8,6 +8,7 @@ import ( client "github.com/coreos/etcd/clientv3" "github.com/fsnotify/fsnotify" "github.com/go-gomail/gomail" + "github.com/k0kubun/pp" "github.com/shunfei/cronsun/db" "github.com/shunfei/cronsun/event" @@ -63,7 +64,7 @@ type Conf struct { // 默认 300 LockTtl int64 - Etcd client.Config + Etcd *etcdConfig Mgo *db.Config Web *webConfig Mail *MailConf @@ -71,6 +72,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 +145,13 @@ 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 + pp.Println(c.Etcd.conf) + if c.Ttl <= 0 { c.Ttl = 10 }