return zero value for proxy server if not detected

This commit is contained in:
Baipyrus 2024-09-12 23:39:02 +02:00
parent 0f285a5534
commit 531285c8c3
2 changed files with 15 additions and 6 deletions

View File

@ -21,9 +21,14 @@ func mapCmdsToStr(commands []*util.Command) string {
func Debug() { func Debug() {
proxy, _ := ReadSystemProxy() proxy, _ := ReadSystemProxy()
proxyServer := proxy.Server
if proxyServer == "" {
proxyServer = "[N/A]"
}
fmt.Println("\nSystem Proxy:") fmt.Println("\nSystem Proxy:")
fmt.Printf("Enabled: %t\n", proxy.Enabled) 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() configs, _ := util.ReadConfigs()
for _, config := range configs { for _, config := range configs {

View File

@ -88,8 +88,10 @@ func ReadSystemProxy() (*Proxy, error) {
} }
// Use entire value if singular server // Use entire value if singular server
proxy := &Proxy{Enabled: enabled, Server: ""}
if !strings.ContainsAny(servers, ";=") { if !strings.ContainsAny(servers, ";=") {
return &Proxy{Enabled: enabled, Server: servers}, nil proxy.Server = servers
return proxy, nil
} }
// Map proxy servers into dictionary // Map proxy servers into dictionary
@ -103,16 +105,18 @@ func ReadSystemProxy() (*Proxy, error) {
// Grab HTTP proxy server first // Grab HTTP proxy server first
if serverDict["http"] != "" { if serverDict["http"] != "" {
return &Proxy{Enabled: enabled, Server: serverDict["http"]}, nil proxy.Server = serverDict["http"]
return proxy, nil
} }
// Grab HTTP proxy server second // Grab HTTP proxy server second
if serverDict["https"] != "" { 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 with empty proxy server ("discarded"; not detected)
return nil, errors.New("You need to configure either HTTP or HTTPS proxy servers to proceed.") return proxy, nil
} }
func SetSystemProxy(state bool) error { func SetSystemProxy(state bool) error {