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.
@@ -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)
+ }
+ return registry.IndexServer
}
- } else if info.IndexServerAddress == "" {
+ 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
