From 63028bf8aa943cb8f6af7fd595d4f48c3186f993 Mon Sep 17 00:00:00 2001 From: Tony Date: Sat, 25 May 2019 15:35:57 +0800 Subject: [PATCH] valid discovery config --- pkg/naming/discovery/discovery.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pkg/naming/discovery/discovery.go b/pkg/naming/discovery/discovery.go index 2f5c4c0e7..c63896f1f 100644 --- a/pkg/naming/discovery/discovery.go +++ b/pkg/naming/discovery/discovery.go @@ -101,7 +101,7 @@ type appInfo struct { lastTs int64 // latest timestamp } -func fixConfig(c *Config) { +func fixConfig(c *Config) error { if len(c.Nodes) == 0 { c.Nodes = strings.Split(env.DiscoveryNodes, ",") } @@ -117,6 +117,17 @@ func fixConfig(c *Config) { if c.Host == "" { c.Host = env.Hostname } + if len(c.Nodes) == 0 || c.Region == "" || c.Zone == "" || c.Env == "" || c.Host == "" { + return fmt.Errorf( + "invalid discovery config nodes:%+s 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. @@ -124,7 +135,9 @@ func New(c *Config) (d *Discovery) { if c == nil { c = new(Config) } - fixConfig(c) + if err := fixConfig(c); err != nil { + panic(err) + } ctx, cancel := context.WithCancel(context.Background()) d = &Discovery{ c: c,