mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-21 09:36:34 -05:00
Feat: vformat supports multi-core processing (#996)
This commit is contained in:
parent
a771e3401a
commit
218f27c9c1
@ -77,31 +77,31 @@ func GetGOBIN() string {
|
||||
return GOBIN
|
||||
}
|
||||
|
||||
func Run(binary string, args []string) (string, error) {
|
||||
func Run(binary string, args []string) ([]byte, error) {
|
||||
cmd := exec.Command(binary, args...)
|
||||
cmd.Env = append(cmd.Env, os.Environ()...)
|
||||
output, cmdErr := cmd.CombinedOutput()
|
||||
if cmdErr != nil {
|
||||
return "", cmdErr
|
||||
return nil, cmdErr
|
||||
}
|
||||
if len(output) > 0 {
|
||||
return string(output), nil
|
||||
}
|
||||
return "", nil
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func RunMany(binary string, args, files []string) {
|
||||
fmt.Println("Processing...")
|
||||
|
||||
maxTasks := make(chan struct{}, runtime.NumCPU())
|
||||
for _, file := range files {
|
||||
args := append(args, file)
|
||||
output, err := Run(binary, args)
|
||||
maxTasks <- struct{}{}
|
||||
go func(file string) {
|
||||
output, err := Run(binary, append(args, file))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
if len(output) > 0 {
|
||||
fmt.Println(output)
|
||||
} else if len(output) > 0 {
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
<-maxTasks
|
||||
}(file)
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,7 +139,7 @@ func main() {
|
||||
goimports = goimportsPath
|
||||
}
|
||||
|
||||
rawFilesSlice := make([]string, 0)
|
||||
rawFilesSlice := make([]string, 0, 1000)
|
||||
walkErr := filepath.Walk("./", func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
Loading…
Reference in New Issue
Block a user