From 531285c8c32f78371163bb7bedeaa27765796006 Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Thu, 12 Sep 2024 23:39:02 +0200 Subject: [PATCH] return zero value for proxy server if not detected --- proxy/debug.go | 7 ++++++- proxy/util.go | 14 +++++++++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/proxy/debug.go b/proxy/debug.go index 3e7c29e..8430d06 100644 --- a/proxy/debug.go +++ b/proxy/debug.go @@ -21,9 +21,14 @@ func mapCmdsToStr(commands []*util.Command) string { func Debug() { proxy, _ := ReadSystemProxy() + proxyServer := proxy.Server + if proxyServer == "" { + proxyServer = "[N/A]" + } + fmt.Println("\nSystem Proxy:") fmt.Printf("Enabled: %t\n", proxy.Enabled) - fmt.Printf("Server: %s\n\n", proxy.Server) + fmt.Printf("Server: %s\n\n", proxyServer) configs, _ := util.ReadConfigs() for _, config := range configs { diff --git a/proxy/util.go b/proxy/util.go index bb74169..59f0e14 100644 --- a/proxy/util.go +++ b/proxy/util.go @@ -88,8 +88,10 @@ func ReadSystemProxy() (*Proxy, error) { } // Use entire value if singular server + proxy := &Proxy{Enabled: enabled, Server: ""} if !strings.ContainsAny(servers, ";=") { - return &Proxy{Enabled: enabled, Server: servers}, nil + proxy.Server = servers + return proxy, nil } // Map proxy servers into dictionary @@ -103,16 +105,18 @@ func ReadSystemProxy() (*Proxy, error) { // Grab HTTP proxy server first if serverDict["http"] != "" { - return &Proxy{Enabled: enabled, Server: serverDict["http"]}, nil + proxy.Server = serverDict["http"] + return proxy, nil } // Grab HTTP proxy server second if serverDict["https"] != "" { - return &Proxy{Enabled: enabled, Server: serverDict["https"]}, nil + proxy.Server = serverDict["https"] + return proxy, nil } - // Throw error on no usable proxy server - return nil, errors.New("You need to configure either HTTP or HTTPS proxy servers to proceed.") + // Return with empty proxy server ("discarded"; not detected) + return proxy, nil } func SetSystemProxy(state bool) error {