-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Advanced Windows features (#213)
* feat: Advanced Windows features * many changes * organizing code * updating CHANGELOG * CR changes Co-authored-by: Pedro Faria De Miranda Pinto <pedro.faria@ifood.com.br> Co-authored-by: Pedro Faria <predofaria@gmail.com>
- Loading branch information
1 parent
cebf2c4
commit 607bfa5
Showing
14 changed files
with
347 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package helper | ||
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
) | ||
|
||
func SetCoreAffinity(pid int, value uint) error { | ||
args := []string{fmt.Sprintf("$Process = Get-Process -Id %d; $Process.ProcessorAffinity=%d", pid, value)} | ||
cmd := exec.Command("PowerShell", args...) | ||
return cmd.Start() | ||
} | ||
|
||
func SetCpuPriority(pid int, p uint) error { | ||
args := []string{"process", "where", fmt.Sprintf("ProcessId=%d", pid), "call", "setpriority", fmt.Sprintf("%d", p)} | ||
cmd := exec.Command("wmic", args...) | ||
return cmd.Start() | ||
} | ||
|
||
func AddFirewallRules(pid, tcp, udp int) error { | ||
if err := addFWRule(pid, tcp, "TCP"); err != nil { | ||
return err | ||
} | ||
|
||
return addFWRule(pid, udp, "UDP") | ||
} | ||
|
||
func addFWRule(pid, port int, t string) error { | ||
args := []string{ | ||
"advfirewall", "firewall", "add", "rule", fmt.Sprintf("name=\"ACCSERVER_%d\"", pid), | ||
"dir=in", "action=allow", fmt.Sprintf("protocol=%s", t), fmt.Sprintf("localport=%d", port), | ||
} | ||
|
||
cmd := exec.Command("netsh.exe", args...) | ||
return cmd.Start() | ||
} | ||
|
||
func DelFirewallRules(pid int) error { | ||
args := []string{"advfirewall", "firewall", "del", "rule", fmt.Sprintf("name=\"ACCSERVER_%d\"", pid)} | ||
cmd := exec.Command("netsh.exe", args...) | ||
return cmd.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.