From 5acdcc3a39872264317f5bbb527995ef4e85dceb Mon Sep 17 00:00:00 2001 From: Tanjin Xu Date: Mon, 22 Jan 2024 10:53:03 -0800 Subject: [PATCH] rework --- go/vt/grpcclient/client_auth_static.go | 30 ++++++++++++-------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/go/vt/grpcclient/client_auth_static.go b/go/vt/grpcclient/client_auth_static.go index f3783527fef..0b1d7ee6557 100644 --- a/go/vt/grpcclient/client_auth_static.go +++ b/go/vt/grpcclient/client_auth_static.go @@ -65,25 +65,23 @@ func AppendStaticAuth(opts []grpc.DialOption) ([]grpc.DialOption, error) { return opts, nil } - if clientCreds == nil { - var err error - once.Do(func() { - var credsData []byte - credsData, err = os.ReadFile(*credsFile) - if err != nil { - return - } - - clientCreds = &StaticAuthClientCreds{} - err = json.Unmarshal(credsData, clientCreds) - if err != nil { - return - } - }) + var err error + once.Do(func() { + var credsData []byte + credsData, err = os.ReadFile(*credsFile) + if err != nil { + return + } + clientCreds = &StaticAuthClientCreds{} + err = json.Unmarshal(credsData, clientCreds) if err != nil { - return nil, err + return } + }) + + if clientCreds == nil || err != nil { + return nil, err } creds := grpc.WithPerRPCCredentials(clientCreds)