mirror of
https://github.com/Baipyrus/ProxySwitcher.git
synced 2024-12-27 05:01:45 +00:00
return zero value for proxy server if not detected
This commit is contained in:
parent
0f285a5534
commit
531285c8c3
@ -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 {
|
||||||
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user