mirror of
https://github.com/go-kratos/kratos.git
synced 2025-03-21 21:27:16 +02:00
Merge pull request #124 from bilibili/valid-discovery-conf
valid discovery config
This commit is contained in:
commit
a7cfb5958d
@ -101,7 +101,7 @@ type appInfo struct {
|
|||||||
lastTs int64 // latest timestamp
|
lastTs int64 // latest timestamp
|
||||||
}
|
}
|
||||||
|
|
||||||
func fixConfig(c *Config) {
|
func fixConfig(c *Config) error {
|
||||||
if len(c.Nodes) == 0 {
|
if len(c.Nodes) == 0 {
|
||||||
c.Nodes = strings.Split(env.DiscoveryNodes, ",")
|
c.Nodes = strings.Split(env.DiscoveryNodes, ",")
|
||||||
}
|
}
|
||||||
@ -117,6 +117,17 @@ func fixConfig(c *Config) {
|
|||||||
if c.Host == "" {
|
if c.Host == "" {
|
||||||
c.Host = env.Hostname
|
c.Host = env.Hostname
|
||||||
}
|
}
|
||||||
|
if len(c.Nodes) == 0 || c.Region == "" || c.Zone == "" || c.Env == "" || c.Host == "" {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"invalid discovery config nodes:%+v region:%s zone:%s deployEnv:%s host:%s",
|
||||||
|
c.Nodes,
|
||||||
|
c.Region,
|
||||||
|
c.Zone,
|
||||||
|
c.Env,
|
||||||
|
c.Host,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// New new a discovery client.
|
// New new a discovery client.
|
||||||
@ -124,7 +135,9 @@ func New(c *Config) (d *Discovery) {
|
|||||||
if c == nil {
|
if c == nil {
|
||||||
c = new(Config)
|
c = new(Config)
|
||||||
}
|
}
|
||||||
fixConfig(c)
|
if err := fixConfig(c); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
d = &Discovery{
|
d = &Discovery{
|
||||||
c: c,
|
c: c,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user