From 69b4eb3986d70faaf499685d322dac5efc68d9db Mon Sep 17 00:00:00 2001 From: xuxiaoliang Date: Sun, 14 Jun 2020 14:37:42 +0800 Subject: [PATCH] alter client config by deffer 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 af5ac3ff70..97cd2216db 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