mirror of https://github.com/docker/cli.git
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 <dave.scott@docker.com>
This commit is contained in:
parent
a82e6868cc
commit
c9d0e47414
|
@ -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 == "" {
|
||||
return registry.IndexServer
|
||||
}
|
||||
if info.IndexServerAddress == "" {
|
||||
if debug.IsEnabled() {
|
||||
fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", serverAddress)
|
||||
fmt.Fprintf(cli.Err(), "Warning: Empty registry endpoint from daemon. Using system default: %s\n", registry.IndexServer)
|
||||
}
|
||||
} else {
|
||||
serverAddress = info.IndexServerAddress
|
||||
return registry.IndexServer
|
||||
}
|
||||
return serverAddress
|
||||
return info.IndexServerAddress
|
||||
}
|
||||
|
||||
// EncodeAuthToBase64 serializes the auth configuration as JSON base64 payload
|
||||
|
|
Loading…
Reference in New Issue