mirror of https://github.com/shunfei/cronsun
Fix etcd configuration json fields
parent
f3897447ff
commit
870fb4a88c
|
@ -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
|
||||
}
|
||||
|
|
23
conf/conf.go
23
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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue