From 173bf888a88fec8a61502f6b77adceff53936f3a Mon Sep 17 00:00:00 2001 From: MohammadReza Palide Date: Tue, 24 Oct 2023 07:37:57 +0000 Subject: [PATCH] fix issue on structure and conditions for fetch config data from online servers --- cmd/skywire-cli/commands/config/gen.go | 45 +++++++++++++------------ cmd/skywire-cli/commands/config/root.go | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/cmd/skywire-cli/commands/config/gen.go b/cmd/skywire-cli/commands/config/gen.go index 9bf3f9de91..eff13423ab 100644 --- a/cmd/skywire-cli/commands/config/gen.go +++ b/cmd/skywire-cli/commands/config/gen.go @@ -497,25 +497,26 @@ var genConfigCmd = &cobra.Command{ log.WithError(err).Error("Failed to fetch servers\n") log.Warn("Falling back on hardcoded servers") } - } - if res.Body != nil { - defer res.Body.Close() //nolint - } - body, err := io.ReadAll(res.Body) - if err != nil { - log.WithError(err).Fatal("Failed to read response\n") - } - //fill in services struct with the response - err = json.Unmarshal(body, &services) - if err != nil { - log.WithError(err).Fatal("Failed to unmarshal json response\n") - } - if !isStdout { - log.Infof("Fetched service endpoints from '%s'", serviceConfURL) - } + } else { + if res.Body != nil { + defer res.Body.Close() //nolint + } + body, err := io.ReadAll(res.Body) + if err != nil { + log.WithError(err).Fatal("Failed to read response\n") + } + //fill in services struct with the response + err = json.Unmarshal(body, &services) + if err != nil { + log.WithError(err).Fatal("Failed to unmarshal json response\n") + } + if !isStdout { + log.Infof("Fetched service endpoints from '%s'", serviceConfURL) + } - // reset the state of isStdout - isStdout = wasStdout + // reset the state of isStdout + isStdout = wasStdout + } } // Read in old config and obtain old secret key or generate a new random secret key @@ -581,11 +582,11 @@ var genConfigCmd = &cobra.Command{ conf.Common.PK = pk dnsServer := utilenv.DNSServer - if services != nil { - if services.DNSServer != "" { - dnsServer = services.DNSServer - } + + if services.DNSServer != "" { + dnsServer = services.DNSServer } + if isDmsgHTTP { dmsghttpConfig := visorconfig.DMSGHTTPName // TODO diff --git a/cmd/skywire-cli/commands/config/root.go b/cmd/skywire-cli/commands/config/root.go index aa6c856552..5300048ca0 100644 --- a/cmd/skywire-cli/commands/config/root.go +++ b/cmd/skywire-cli/commands/config/root.go @@ -50,7 +50,7 @@ var ( disableApps string isBestProtocol bool serviceConfURL string - services *visorconfig.Services + services visorconfig.Services isForce bool isHide bool isAll bool