mirror of https://github.com/shunfei/cronsun
commit
6c8952270a
|
@ -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
|
||||
}
|
||||
|
|
21
conf/conf.go
21
conf/conf.go
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue