From 45a983ef2163aa07e7f64e1b76a14984931039d2 Mon Sep 17 00:00:00 2001
From: xuxiaoliang <xuxiaoliang03411@Hellobike.com>
Date: Sun, 14 Jun 2020 14:39:26 +0800
Subject: [PATCH] alter client config by defer delay check

---
 protocol/grpc/client.go | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go
index af5ac3ff7..97cd2216d 100644
--- a/protocol/grpc/client.go
+++ b/protocol/grpc/client.go
@@ -41,11 +41,22 @@ var (
 
 func init() {
 	// load clientconfig from consumer_config
-	// default use grpc
-	defaultClientConfig := GetDefaultClientConfig()
-	clientConf = &defaultClientConfig
 	consumerConfig := config.GetConsumerConfig()
 
+	clientConfig := GetClientConfig()
+	clientConf = &clientConfig
+
+	// check client config and decide whether to use the default config
+	defer func() {
+		if clientConf == nil || len(clientConf.ContentSubType) == 0 {
+			defaultClientConfig := GetDefaultClientConfig()
+			clientConf = &defaultClientConfig
+		}
+		if err := clientConf.Validate(); err != nil {
+			panic(err)
+		}
+	}()
+
 	if consumerConfig.ApplicationConfig == nil {
 		return
 	}
@@ -69,12 +80,6 @@ func init() {
 		}
 	}
 
-	if clientConf == nil || len(clientConf.ContentSubType) == 0 {
-		clientConf = &defaultClientConfig
-	}
-	if err := clientConf.Validate(); err != nil {
-		panic(err)
-	}
 }
 
 // Client return grpc connection and warp service stub
-- 
GitLab