Merge pull request #124 from bilibili/valid-discovery-conf

valid discovery config
pull/127/head
Tony 6 years ago committed by GitHub
commit a7cfb5958d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      pkg/naming/discovery/discovery.go

@ -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…
Cancel
Save