From 39a0a6d828807046066f708c9fa649d15c1e9a4a Mon Sep 17 00:00:00 2001 From: Baipyrus Date: Tue, 1 Oct 2024 20:13:47 +0200 Subject: [PATCH] passing a command by reference to 'processVars' instead of return types --- proxy/util.go | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/proxy/util.go b/proxy/util.go index 5da197d..8e7a119 100644 --- a/proxy/util.go +++ b/proxy/util.go @@ -9,21 +9,16 @@ import ( "golang.org/x/sys/windows/registry" ) -func processVars(isVariableType bool, args []string, configCmd string) ([]string, string) { - var configArgs []string - - for _, arg := range args { - // If not replacable, append - if !isVariableType { - configArgs = append(configArgs, arg) - continue - } - - // Replace specific "ProxySwitcher Argument" in command - configCmd = strings.Replace(configCmd, "$PRSW_ARG", arg, 1) +func processVars(cmd *util.Command, isVariableType bool) { + // If not a variable type, return early as there's nothing to replace + if !isVariableType { + return } - return configArgs, configCmd + // Replace specific $PRSW_ARG in the command's Name with each argument + for _, arg := range cmd.Arguments { + cmd.Name = strings.Replace(cmd.Name, "$PRSW_ARG", arg, 1) + } } func injectProxy(configArgs []string, configCmd, proxyServer string, variant *util.Variant) ([]string, string) { @@ -68,8 +63,8 @@ func generateCommands(base string, variants []*util.Variant, proxyServer string) Arguments: append([]string{}, variant.Arguments...), } - configArgs, configCmd := processVars(isVariableType, cmd.Arguments, cmd.Name) - configArgs, configCmd = injectProxy(configArgs, configCmd, proxyServer, variant) + processVars(cmd, isVariableType) + configArgs, configCmd := injectProxy(cmd.Arguments, cmd.Name, proxyServer, variant) commands = append(commands, &util.Command{Name: configCmd, Arguments: configArgs}) }