From c9d0e4741481c98c1aba337ce377d205b8905c4c Mon Sep 17 00:00:00 2001 From: David Scott Date: Thu, 28 Mar 2019 21:08:00 +0000 Subject: [PATCH] Simplify ElectAuthServer Instead of using an `if else if else`, switch to a sequence of independent `if` blocks containing a `return`. Instead of defining a return variable and updating it in the `if` blocks and returning at the end, make each `if` block return the desired value independenly. Signed-off-by: David Scott --- cli/command/registry.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/cli/command/registry.go b/cli/command/registry.go index 90189b9482..161962636e 100644 --- a/cli/command/registry.go +++ b/cli/command/registry.go @@ -28,21 +28,22 @@ func ElectAuthServer(ctx context.Context, cli Cli) string { // used. This is essential in cross-platforms environment, where for // example a Linux client might be interacting with a Windows daemon, hence // the default registry URL might be Windows specific. - serverAddress := registry.IndexServer - if info, err := cli.Client().Info(ctx); err != nil { + info, err := cli.Client().Info(ctx) + if err != nil { // Daemon is not responding so use system default. if debug.IsEnabled() { // Only report the warning if we're in debug mode to prevent nagging during engine initialization workflows - fmt.Fprintf(cli.Err(), "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, serverAddress) + fmt.Fprintf(cli.Err(), "Warning: failed to get default registry endpoint from daemon (%v). Using system default: %s\n", err, registry.IndexServer) } - } else if info.IndexServerAddress == "" { - if debug.IsEnabled() { - fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", serverAddress) - } - } else { - serverAddress = info.IndexServerAddress + return registry.IndexServer } - return serverAddress + if info.IndexServerAddress == "" { + if debug.IsEnabled() { + fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", registry.IndexServer) + } + return registry.IndexServer + } + return info.IndexServerAddress } // EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload