Merge pull request #18 from Baipyrus/variant-surround-char

Default Config - Environment Variable Proxy Setters
This commit is contained in:
Baipyrus 2024-09-23 18:58:55 +02:00 committed by GitHub
commit a957fdcc8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 0 deletions

View File

@ -7,11 +7,13 @@
"args": [ "args": [
"http_proxy" "http_proxy"
], ],
"surround": "\"",
"type": "variable" "type": "variable"
}, { }, {
"args": [ "args": [
"https_proxy" "https_proxy"
], ],
"surround": "\"",
"type": "variable" "type": "variable"
} }
], ],

View File

@ -2,6 +2,7 @@ package proxy
import ( import (
"errors" "errors"
"fmt"
"strings" "strings"
"github.com/Baipyrus/ProxySwitcher/util" "github.com/Baipyrus/ProxySwitcher/util"
@ -31,6 +32,11 @@ func applyProxy(configArgs []string, configCmd, proxyServer string, variant *uti
return configArgs, configCmd return configArgs, configCmd
} }
// Surround 'proxyServer' with any given string, if provided
if variant.Surround != "" {
proxyServer = fmt.Sprintf("%[1]s%[2]s%[1]s", variant.Surround, proxyServer)
}
// Insert proxy only on last VARIABLE type // Insert proxy only on last VARIABLE type
if variant.Type == util.VARIABLE && strings.Count(configCmd, "$PRSW_ARG") == 1 { if variant.Type == util.VARIABLE && strings.Count(configCmd, "$PRSW_ARG") == 1 {
configCmd = strings.Replace(configCmd, "$PRSW_ARG", proxyServer, 1) configCmd = strings.Replace(configCmd, "$PRSW_ARG", proxyServer, 1)

View File

@ -18,6 +18,7 @@ type Variant struct {
Arguments []string `json:"args"` Arguments []string `json:"args"`
Type VariantType `json:"type,omitempty"` Type VariantType `json:"type,omitempty"`
Equator string `json:"equator,omitempty"` Equator string `json:"equator,omitempty"`
Surround string `json:"surround,omitempty"`
DiscardProxy bool `json:"discard,omitempty"` DiscardProxy bool `json:"discard,omitempty"`
} }